summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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 'src')
-rw-r--r--src/cli/report.cpp5
-rw-r--r--src/daemon/Settings.cpp39
2 files changed, 23 insertions, 21 deletions
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 */
}