summaryrefslogtreecommitdiffstats
path: root/lib/utils/Plugin.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-22 17:25:15 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-22 17:25:15 +0200
commitff3392b9c9471cd6d837a9ab3abe135ab2d75edf (patch)
tree65595bf77f2bacc9315f20e6718356193f61cfe4 /lib/utils/Plugin.cpp
parentb74cfbee13b9d2723dd48fe3e2a049fc55129699 (diff)
downloadabrt-ff3392b9c9471cd6d837a9ab3abe135ab2d75edf.tar.gz
abrt-ff3392b9c9471cd6d837a9ab3abe135ab2d75edf.tar.xz
abrt-ff3392b9c9471cd6d837a9ab3abe135ab2d75edf.zip
introduce and use xmalloc_fgets/fgetline
This fixes problems of having long lines truncated - and we do have very long lines sometimes - curl errors with HTML, list of debuginfos etc. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/utils/Plugin.cpp')
-rw-r--r--lib/utils/Plugin.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/utils/Plugin.cpp b/lib/utils/Plugin.cpp
index da55bdbf..8c00e609 100644
--- a/lib/utils/Plugin.cpp
+++ b/lib/utils/Plugin.cpp
@@ -56,7 +56,7 @@ const map_plugin_settings_t& CPlugin::GetSettings()
}
bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
- bool skipKeysWithoutValue /*= true*/)
+ bool skipKeysWithoutValue /*= true*/)
{
FILE *fp = stdin;
if (strcmp(pPath, "-") != 0)
@@ -66,16 +66,15 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
return false;
}
- char line[512];
- while (fgets(line, sizeof(line), fp))
+ char *line;
+ while ((line = xmalloc_fgetline(fp)) != NULL)
{
- strchrnul(line, '\n')[0] = '\0';
unsigned ii;
bool is_value = false;
bool valid = false;
bool in_quote = false;
- std::string key;
- std::string value;
+ std::string key;
+ std::string value;
for (ii = 0; line[ii] != '\0'; ii++)
{
if (line[ii] == '"')
@@ -106,23 +105,26 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
}
}
- /* Skip broken or empty lines. */
- if (!valid)
- continue;
+ /* Skip broken or empty lines. */
+ if (!valid)
+ goto free_line;
- /* Skip lines with empty key. */
- if (key.length() == 0)
- continue;
+ /* Skip lines with empty key. */
+ if (key.length() == 0)
+ goto free_line;
- if (skipKeysWithoutValue && value.length() == 0)
- continue;
+ if (skipKeysWithoutValue && value.length() == 0)
+ goto free_line;
- /* Skip lines with unclosed quotes. */
+ /* Skip lines with unclosed quotes. */
if (in_quote)
- continue;
+ goto free_line;
- pSettings[key] = value;
+ pSettings[key] = value;
+ free_line:
+ free(line);
}
+
if (fp != stdin)
fclose(fp);
return true;