diff options
author | wpaul <wpaul@FreeBSD.org> | 1997-11-16 03:02:39 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1997-11-16 03:02:39 +0000 |
commit | 5a4ed48dff198410fbdf2c46f101186d32cfb296 (patch) | |
tree | 624861e4f689293a75a4259f0ea3a970a23aa1b2 /lib/libc/gen/getnetgrent.c | |
parent | 0bdadfcd1b48907adfec25bcb5b54947ce4c9654 (diff) | |
download | FreeBSD-src-5a4ed48dff198410fbdf2c46f101186d32cfb296.zip FreeBSD-src-5a4ed48dff198410fbdf2c46f101186d32cfb296.tar.gz |
Close PR #4867: improve _listmatch() to avoid returning false positives.
PR: 4867
Diffstat (limited to 'lib/libc/gen/getnetgrent.c')
-rw-r--r-- | lib/libc/gen/getnetgrent.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 605dd50..cc04f2f 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -276,17 +276,24 @@ endnetgrent() #ifdef YP static int _listmatch(list, group, len) -char *list, *group; -int len; + char *list, *group; + int len; { - char *ptr = list; - - while ( (ptr = strstr(ptr, group)) ) { - - ptr += strlen(group); - - if (*ptr == ',' || *ptr == '\0') + char *ptr = list, *cptr; + int glen = strlen(group); + + /* skip possible leading whitespace */ + while(isspace(*ptr)) + ptr++; + + while (ptr < list + len) { + cptr = ptr; + while(*ptr != ',' && !isspace(*ptr)) + ptr++; + if (strncmp(cptr, group, glen) == 0 && glen == (ptr - cptr)) return(1); + while(*ptr == ',' || isspace(*ptr)) + ptr++; } return(0); |