summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/plugins/Bugzilla.cpp13
-rw-r--r--lib/plugins/CCpp.cpp15
-rw-r--r--lib/plugins/FileTransfer.cpp8
-rw-r--r--lib/plugins/Logger.cpp6
-rw-r--r--lib/plugins/RHTSupport.cpp15
-rw-r--r--lib/plugins/ReportUploader.cpp6
-rw-r--r--lib/utils/Plugin.cpp36
-rw-r--r--lib/utils/hooklib.c20
-rw-r--r--src/cli/report.cpp5
-rw-r--r--src/daemon/Settings.cpp39
10 files changed, 82 insertions, 81 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);
}
}
diff --git a/src/cli/report.cpp b/src/cli/report.cpp
index 46205f7e..b6edef9a 100644
--- a/src/cli/report.cpp
+++ b/src/cli/report.cpp
@@ -542,10 +542,9 @@ static bool ask_yesno(const char *question)
/* The response might take more than 1 char in non-latin scripts. */
const char *yes = _("y");
const char *no = _("N");
- char *full_question = xasprintf("%s [%s/%s]: ", question, yes, no);
- printf(full_question);
- free(full_question);
+ printf("%s [%s/%s]: ", question, yes, no);
fflush(NULL);
+
char answer[16];
fgets(answer, sizeof(answer), stdin);
/* Use strncmp here because the answer might contain a newline as
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 */
}