diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-22 17:25:15 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-22 17:25:15 +0200 |
commit | ff3392b9c9471cd6d837a9ab3abe135ab2d75edf (patch) | |
tree | 65595bf77f2bacc9315f20e6718356193f61cfe4 /src/daemon/Settings.cpp | |
parent | b74cfbee13b9d2723dd48fe3e2a049fc55129699 (diff) | |
download | abrt-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 'src/daemon/Settings.cpp')
-rw-r--r-- | src/daemon/Settings.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index a85bb419..1be85954 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -347,14 +347,13 @@ static void LoadGPGKeys() /* every line is one key * FIXME: make it more robust, it doesn't handle comments */ - char line[512]; - while (fgets(line, sizeof(line), fp)) + char *line; + while ((line = xmalloc_fgetline(fp)) != NULL) { if (line[0] == '/') // probably the begining of path, so let's handle it as a key - { - strchrnul(line, '\n')[0] = '\0'; - g_settings_setOpenGPGPublicKeys = g_list_append(g_settings_setOpenGPGPublicKeys, xstrdup(line)); - } + g_settings_setOpenGPGPublicKeys = g_list_append(g_settings_setOpenGPGPublicKeys, line); + else + free(line); } fclose(fp); } @@ -366,12 +365,11 @@ static void LoadGPGKeys() */ static int ReadConfigurationFromFile(FILE *fp) { - char line[512]; + char *line; std::string section; int lineno = 0; - while (fgets(line, sizeof(line), fp)) + while ((line = xmalloc_fgetline(fp)) != NULL) { - strchrnul(line, '\n')[0] = '\0'; ++lineno; bool is_key = true; bool is_section = false; @@ -422,12 +420,12 @@ static int ReadConfigurationFromFile(FILE *fp) continue; } value += line[ii]; - } + } /* for */ if (is_quote) { error_msg("abrt.conf: Invalid syntax on line %d", lineno); - return 1; /* error */ + goto return_error; } if (is_section) @@ -435,9 +433,9 @@ static int ReadConfigurationFromFile(FILE *fp) if (line[ii] != ']') /* section not closed */ { error_msg("abrt.conf: Section not closed on line %d", lineno); - return 1; /* error */ + goto return_error; } - continue; + goto free_line; } if (is_key) @@ -445,14 +443,14 @@ static int ReadConfigurationFromFile(FILE *fp) if (!value.empty()) /* the key is stored in value */ { error_msg("abrt.conf: Invalid syntax on line %d", lineno); - return 1; /* error */ + goto return_error; } - continue; + goto free_line; } - else if (key.empty()) /* A line without key: " = something" */ + if (key.empty()) /* A line without key: " = something" */ { error_msg("abrt.conf: Invalid syntax on line %d", lineno); - return 1; /* error */ + goto return_error; } if (section == SECTION_COMMON) @@ -476,9 +474,14 @@ static int ReadConfigurationFromFile(FILE *fp) else { error_msg("abrt.conf: Ignoring entry in invalid section [%s]", section.c_str()); + return_error: + free(line); return 1; /* error */ } - } + free_line: + free(line); + } /* while */ + return 0; /* success */ } |