Comments
Patch
@@ -123,6 +123,7 @@ int config_parse_file(const char *section, struct config_keyset *kset)
unsigned int i;
char linebuf[LINE_LEN+1];
char *line = linebuf;
+ int linenum = 0;
pr_debug("%s: section='%s' file='%s'\n", __func__, section, fname);
@@ -135,9 +136,16 @@ int config_parse_file(const char *section, struct config_keyset *kset)
char wordbuf[LINE_LEN];
char *wordend;
+ linenum++;
if (*line == '#')
continue;
+ /* if line was fetch completely, string ends with '\n' */
+ if (! strchr(line, '\n')) {
+ ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
+ return -ERRTOOLONG;
+ }
+
if (!(wordend = get_word(line, " \t\n[]", (char *) wordbuf)))
continue;
pr_debug("word: \"%s\"\n", wordbuf);
@@ -159,10 +167,17 @@ int config_parse_file(const char *section, struct config_keyset *kset)
char wordbuf[LINE_LEN];
char *wordend;
+ linenum++;
pr_debug("line read: %s\n", line);
if (*line == '#')
continue;
+ /* if line was fetch completely, string ends with '\n' */
+ if (! strchr(line, '\n')) {
+ ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
+ return -ERRTOOLONG;
+ }
+
if (!(wordend = get_word(line, " =\t\n", (char *) &wordbuf)))
continue;
@@ -990,9 +990,13 @@ static int parse_conffile(const char *section, struct config_keyset *ce)
"section \"%s\" not found\n", section);
break;
case -ERRTOOLONG:
- ulogd_log(ULOGD_ERROR,
- "too long string value for key \"%s\"\n",
- config_errce->key);
+ if (config_errce->key)
+ ulogd_log(ULOGD_ERROR,
+ "too long string value for key \"%s\"\n",
+ config_errce->key);
+ else
+ ulogd_log(ULOGD_ERROR,
+ "too long string value\n");
break;
}
return 1;
Line length in configuration file is limited to 255 due to the use of a static buffer for line reading. Accepting too long line without warning as it is currently done could result in some unexplainable failure. This patch adds error handling and reject configuration file if a non comment line is longer than the maximum value. Signed-off-by: Eric Leblond <eric@regit.org> --- src/conffile.c | 15 +++++++++++++++ src/ulogd.c | 10 +++++++--- 2 files changed, 22 insertions(+), 3 deletions(-)