summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Leblond <eric@regit.org>2013-02-09 21:36:48 +0100
committerEric Leblond <eric@regit.org>2013-02-18 16:03:06 +0100
commit168fb53664894220e3344e4ec4e89f16e699a989 (patch)
treec5bf964c7dd96f1de4da0fc939780e23356c1d67
parentc9f381c03e022a4d468164b94f00ed78322b9e38 (diff)
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.
-rw-r--r--include/ulogd/conffile.h1
-rw-r--r--src/conffile.c20
-rw-r--r--src/ulogd.c9
3 files changed, 29 insertions, 1 deletions
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;
}