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 /lib | |
| 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 'lib')
| -rw-r--r-- | lib/plugins/Bugzilla.cpp | 13 | ||||
| -rw-r--r-- | lib/plugins/CCpp.cpp | 15 | ||||
| -rw-r--r-- | lib/plugins/FileTransfer.cpp | 8 | ||||
| -rw-r--r-- | lib/plugins/Logger.cpp | 6 | ||||
| -rw-r--r-- | lib/plugins/RHTSupport.cpp | 15 | ||||
| -rw-r--r-- | lib/plugins/ReportUploader.cpp | 6 | ||||
| -rw-r--r-- | lib/utils/Plugin.cpp | 36 | ||||
| -rw-r--r-- | lib/utils/hooklib.c | 20 |
8 files changed, 59 insertions, 60 deletions
diff --git a/lib/plugins/Bugzilla.cpp b/lib/plugins/Bugzilla.cpp index 8d895bad..452d7a58 100644 --- a/lib/plugins/Bugzilla.cpp +++ b/lib/plugins/Bugzilla.cpp @@ -120,21 +120,22 @@ string CReporterBugzilla::Report(const map_crash_data_t& crash_data, /* Consume log from stdout */ string bug_status; - char buf[512]; - while (fgets(buf, sizeof(buf), fp)) + char *buf; + while ((buf = xmalloc_fgetline(fp)) != NULL) { - strchrnul(buf, '\n')[0] = '\0'; if (strncmp(buf, "STATUS:", 7) == 0) bug_status = buf + 7; else if (strncmp(buf, "EXCEPT:", 7) == 0) { + CABRTException e(EXCEP_PLUGIN, "%s", buf + 7); + free(buf); fclose(fp); waitpid(pid, NULL, 0); - throw CABRTException(EXCEP_PLUGIN, "%s", buf + 7); + throw e; } - else - update_client("%s", buf); + update_client("%s", buf); + free(buf); } fclose(fp); /* this also closes pipefds[0] */ diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index 642d97e9..ed5ab3b6 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -154,21 +154,14 @@ static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginf return NULL; } - /* With 126 debuginfos I've seen lines 9k+ chars long... - * yet, having it truly unlimited is bad too, - * therefore we are using LARGE, but still limited buffer. - */ - char *buff = (char*) xmalloc(64*1024); - + char *buff; struct strbuf *buf_build_ids = strbuf_new(); - - while (fgets(buff, 64*1024, pipeout_fp)) + while ((buff = xmalloc_fgetline(pipeout_fp)) != NULL) { - strchrnul(buff, '\n')[0] = '\0'; - if (strncmp(buff, "MISSING:", 8) == 0) { strbuf_append_strf(buf_build_ids, "Debuginfo absent: %s\n", buff + 8); + free(buff); continue; } @@ -183,8 +176,8 @@ static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginf VERB1 log("%s", buff); update_client("%s", buff); } + free(buff); } - free(buff); fclose(pipeout_fp); int status = 0; diff --git a/lib/plugins/FileTransfer.cpp b/lib/plugins/FileTransfer.cpp index 4e4b5818..d964bc9d 100644 --- a/lib/plugins/FileTransfer.cpp +++ b/lib/plugins/FileTransfer.cpp @@ -280,14 +280,13 @@ void CFileTransfer::Run(const char *pActionDir, const char *pArgs, int force) goto del_tmp_dir; } - char dirname[PATH_MAX]; - while (fgets(dirname, sizeof(dirname), dirlist) != NULL) + char *dirname; + while ((dirname = xmalloc_fgetline(dirlist)) != NULL) { - strchrnul(dirname, '\n')[0] = '\0'; string archivename = ssprintf("%s/%s-%s%s", tmpdir_name, hostname, DirBase(dirname).c_str(), m_sArchiveType.c_str()); try { - VERB3 log("Creating archive '%s' of dir '%s'", archivename.c_str(), dirname); + VERB3 log("Creating archive '%s' of dir '%s'", archivename.c_str(), dirname); CreateArchive(archivename.c_str(), dirname); VERB3 log("Sending archive to '%s'", m_sURL.c_str()); SendFile(m_sURL.c_str(), archivename.c_str()); @@ -298,6 +297,7 @@ void CFileTransfer::Run(const char *pActionDir, const char *pArgs, int force) } VERB3 log("Deleting archive '%s'", archivename.c_str()); unlink(archivename.c_str()); + free(dirname); } fclose(dirlist); diff --git a/lib/plugins/Logger.cpp b/lib/plugins/Logger.cpp index 2985208e..8a47319f 100644 --- a/lib/plugins/Logger.cpp +++ b/lib/plugins/Logger.cpp @@ -105,10 +105,10 @@ string CLogger::Report(const map_crash_data_t& crash_data, FILE *fp = fdopen(pipefds[0], "r"); if (!fp) die_out_of_memory(); - char buf[512]; - while (fgets(buf, sizeof(buf), fp)) + char *buf; + while ((buf = xmalloc_fgets(fp)) != NULL) { - full_write_str(fd, buf); + full_write_str(fd, buf); } fclose(fp); /* this also closes pipefds[0] */ /* wait for child to actually exit, and prevent leaving a zombie behind */ diff --git a/lib/plugins/RHTSupport.cpp b/lib/plugins/RHTSupport.cpp index 5c9109e7..c7a3c060 100644 --- a/lib/plugins/RHTSupport.cpp +++ b/lib/plugins/RHTSupport.cpp @@ -111,22 +111,23 @@ string CReporterRHticket::Report(const map_crash_data_t& crash_data, die_out_of_memory(); /* Consume log from stdout */ - std::string bug_status; - char buf[512]; - while (fgets(buf, sizeof(buf), fp)) + string bug_status; + char *buf; + while ((buf = xmalloc_fgetline(fp)) != NULL) { - strchrnul(buf, '\n')[0] = '\0'; if (strncmp(buf, "STATUS:", 7) == 0) bug_status = buf + 7; else if (strncmp(buf, "EXCEPT:", 7) == 0) { + CABRTException e(EXCEP_PLUGIN, "%s", buf + 7); + free(buf); fclose(fp); waitpid(pid, NULL, 0); - throw CABRTException(EXCEP_PLUGIN, "%s", buf + 7); + throw e; } - else - update_client("%s", buf); + update_client("%s", buf); + free(buf); } fclose(fp); /* this also closes pipefds[0] */ diff --git a/lib/plugins/ReportUploader.cpp b/lib/plugins/ReportUploader.cpp index cab2adab..4100e996 100644 --- a/lib/plugins/ReportUploader.cpp +++ b/lib/plugins/ReportUploader.cpp @@ -55,11 +55,11 @@ static string ReadCommand(const char *cmd) } string result; - char buff[1024]; - while (fgets(buff, sizeof(buff), fp) != NULL) + char *buff; + while ((buff = xmalloc_fgetline(fp)) != NULL) { - strchrnul(buff, '\n')[0] = '\0'; result += buff; + free(buff); } int retcode = pclose(fp); 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); } } |
