From ff3392b9c9471cd6d837a9ab3abe135ab2d75edf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 17:25:15 +0200 Subject: 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 --- lib/utils/Plugin.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'lib/utils/Plugin.cpp') 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; -- cgit