]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
Add handling of too long line and arguments.
authorEric Leblond <eric@regit.org>
Sat, 9 Feb 2013 20:36:48 +0000 (21:36 +0100)
committerEric Leblond <eric@regit.org>
Mon, 18 Feb 2013 15:03:06 +0000 (16:03 +0100)
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
src/conffile.c
src/ulogd.c

index 0b8ac0e59b56f53f332491477e44ad8dad66fe3b..69a6f7072aa9f562a977b0447b93c875e885a908 100644 (file)
@@ -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 */
index 616d7a946e164e5e71930c9c9ae8b04a11f144f5..b8e82a84c5fc1663e424c450d24c0bc0991b3d3b 100644 (file)
@@ -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:
index f8c8ed0fcf046ee5f6547b70f8a2ba1f545bc4d1..e09ba9e0b97e5191e68a5f25a1ddc532cb7a4ffd 100644 (file)
@@ -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;
 }