Also let parse_toggle_state() reject values like '1[insert garbage here]'
authorFabian Keil <fk@fabiankeil.de>
Fri, 8 Jul 2011 13:29:22 +0000 (13:29 +0000)
committerFabian Keil <fk@fabiankeil.de>
Fri, 8 Jul 2011 13:29:22 +0000 (13:29 +0000)
loadcfg.c

index 6f39e17..2369cc7 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.113 2011/07/08 13:27:31 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.114 2011/07/08 13:29:06 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
@@ -297,6 +297,7 @@ static int parse_toggle_state(const char *name, const char *value)
 {
    int toggle_state;
    assert(name != NULL);
+   assert(value != NULL);
 
    if ((value == NULL) || (*value == '\0'))
    {
@@ -305,7 +306,11 @@ static int parse_toggle_state(const char *name, const char *value)
 
    toggle_state = atoi(value);
 
-   if ((toggle_state != 0) && (toggle_state != 1))
+   /*
+    * Also check the length as atoi() doesn't mind
+    * garbage after a valid integer, but we do.
+    */
+   if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
    {
       log_error(LOG_LEVEL_FATAL,
          "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",