From 168fb53664894220e3344e4ec4e89f16e699a989 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 9 Feb 2013 21:36:48 +0100 Subject: Add handling of too long line and arguments. When an argument or a line is too long, it can not be store into ulogd configuration and this must results in a error. --- include/ulogd/conffile.h | 1 + src/conffile.c | 20 +++++++++++++++++++- src/ulogd.c | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ulogd/conffile.h b/include/ulogd/conffile.h index 0b8ac0e..69a6f70 100644 --- a/include/ulogd/conffile.h +++ b/include/ulogd/conffile.h @@ -18,6 +18,7 @@ enum { ERRMAND, /* mandatory option not found */ ERRUNKN, /* unknown config key */ ERRSECTION, /* section not found */ + ERRTOOLONG, /* string too long */ }; /* maximum line length of config file entries */ diff --git a/src/conffile.c b/src/conffile.c index 616d7a9..b8e82a8 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -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; @@ -197,7 +212,10 @@ int config_parse_file(const char *section, struct config_keyset *kset) if (strlen(args) < CONFIG_VAL_STRING_LEN ) { strcpy(ce->u.string, args); - /* FIXME: what if not ? */ + } else { + config_errce = ce; + err = -ERRTOOLONG; + goto cpf_error; } break; case CONFIG_TYPE_INT: diff --git a/src/ulogd.c b/src/ulogd.c index f8c8ed0..e09ba9e 100644 --- a/src/ulogd.c +++ b/src/ulogd.c @@ -989,6 +989,15 @@ static int parse_conffile(const char *section, struct config_keyset *ce) ulogd_log(ULOGD_ERROR, "section \"%s\" not found\n", section); break; + case -ERRTOOLONG: + if (config_errce->key) + ulogd_log(ULOGD_ERROR, + "string value too long for key \"%s\"\n", + config_errce->key); + else + ulogd_log(ULOGD_ERROR, + "string value is too long\n"); + break; } return 1; } -- cgit v1.2.3