]> granicus.if.org Git - sudo/commitdiff
o Roll our own loop instead of using strpbrk() for better grokability
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 30 Dec 2001 18:40:09 +0000 (18:40 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 30 Dec 2001 18:40:09 +0000 (18:40 +0000)
o When adding to a list we must malloc() and use memcpy(), not strdup()
  since we must only copy len bytes from str.

defaults.c

index 540cc07d3eb4f2dc436416031440c23f0d48dce5..628bd7fb0a2975d5987d949ab473d65e817a26c9 100644 (file)
@@ -585,16 +585,19 @@ store_list(str, def, op)
 
     /* Split str into multiple space-separated words and act on each one. */
     if (op != FALSE) {
-       for (start = str; isblank(*start); start++)
-           ;
-       while ((end = strpbrk(start, " \t"))) {
-           list_op(start, end - start, def, op == '-' ? delete : add);
-           start = end;
-           for (; isblank(*start); start++)
+       end = str;
+       do {
+           /* Remove leading blanks, if nothing but blanks we are done. */
+           for (start = end; isblank(*start); start++)
                ;
-       }
-       if (*start)
-           list_op(start, strlen(start), def, op == '-' ? delete : add);
+           if (*start == '\0')
+               break;
+
+           /* Find end position and perform operation. */
+           for (end = start; *end && !isblank(*end); end++) 
+               ;
+           list_op(start, end - start, def, op == '-' ? delete : add);
+       } while (*end++ != '\0');
     }
     return(TRUE);
 }
@@ -773,7 +776,9 @@ list_op(val, len, def, op)
     /* Add new node to the head of the list. */
     if (op == add) {
        cur = emalloc(sizeof(struct list_member));
-       cur->value = estrdup(val);
+       cur->value = emalloc(len + 1);
+       (void) memcpy(cur->value, val, len);
+       cur->value[len] = '\0';
        cur->next = def->sd_un.list;
        def->sd_un.list = cur;
     }