summaryrefslogtreecommitdiffstats
path: root/lib/utils
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
parentb74cfbee13b9d2723dd48fe3e2a049fc55129699 (diff)
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')
-rw-r--r--lib/utils/Plugin.cpp36
-rw-r--r--lib/utils/hooklib.c20
2 files changed, 30 insertions, 26 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;
diff --git a/lib/utils/hooklib.c b/lib/utils/hooklib.c
index 6494c039..062e3ddb 100644
--- a/lib/utils/hooklib.c
+++ b/lib/utils/hooklib.c
@@ -25,10 +25,10 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
if (!fp)
return;
- char line[256];
while (1)
{
- if (fgets(line, sizeof(line), fp) == NULL)
+ char *line = xmalloc_fgetline(fp);
+ if (!line)
{
fclose(fp);
if (additional_conf)
@@ -44,7 +44,6 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
break;
}
- strchrnul(line, '\n')[0] = '\0';
const char *p = skip_whitespace(line);
#undef DIRECTIVE
#define DIRECTIVE "MaxCrashReportsSize"
@@ -52,7 +51,7 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
{
p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
if (*p != '=')
- continue;
+ goto free_line;
p = skip_whitespace(p + 1);
if (isdigit(*p))
{
@@ -60,7 +59,7 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
* kicks in first, and we don't "fight" with it. */
*setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4;
}
- continue;
+ goto free_line;
}
#undef DIRECTIVE
#define DIRECTIVE "MakeCompatCore"
@@ -68,10 +67,10 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
{
p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
if (*p != '=')
- continue;
+ goto free_line;
p = skip_whitespace(p + 1);
*setting_MakeCompatCore = string_to_bool(p);
- continue;
+ goto free_line;
}
#undef DIRECTIVE
#define DIRECTIVE "SaveBinaryImage"
@@ -79,13 +78,16 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi
{
p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
if (*p != '=')
- continue;
+ goto free_line;
p = skip_whitespace(p + 1);
*setting_SaveBinaryImage = string_to_bool(p);
- continue;
+ goto free_line;
}
#undef DIRECTIVE
/* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */
+
+ free_line:
+ free(line);
}
}