From f48bc662390b27f2e1ebfc24ce66c32e7a1ac379 Mon Sep 17 00:00:00 2001 From: Steve Price Date: Sun, 1 Mar 1998 18:49:37 +0000 Subject: [PATCH] Replace previous commit with a check disallowing ptr from running off the end of the list variable. PR: 5345, 5610 Submitted by: nagao@cs.titech.ac.jp --- lib/libc/gen/getnetgrent.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index da6d44d384c..cc33d1f4e6d 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -286,21 +286,14 @@ static int _listmatch(list, group, len) while(isspace(*ptr)) ptr++; - if (strchr(list, ',') == NULL) { - if (strncmp(ptr, group, glen) == 0) { + while (ptr < list + len) { + cptr = ptr; + while(*ptr != ',' && *ptr != '\0' && !isspace(*ptr)) + ptr++; + if (strncmp(cptr, group, glen) == 0 && glen == (ptr - cptr)) return(1); - } - } else { - 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++; - } + while(*ptr == ',' || isspace(*ptr)) + ptr++; } return(0);