From: Todd C. Miller Date: Sun, 30 Dec 2001 18:40:09 +0000 (+0000) Subject: o Roll our own loop instead of using strpbrk() for better grokability X-Git-Tag: SUDO_1_6_4~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8dc87eeb226a5fe8f655fd14d186ba96ad799636;p=sudo o Roll our own loop instead of using strpbrk() for better grokability o When adding to a list we must malloc() and use memcpy(), not strdup() since we must only copy len bytes from str. --- diff --git a/defaults.c b/defaults.c index 540cc07d3..628bd7fb0 100644 --- a/defaults.c +++ b/defaults.c @@ -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; }