diff options
author | kib <kib@FreeBSD.org> | 2012-06-16 13:10:22 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-06-16 13:10:22 +0000 |
commit | a7ca300f12a749e66f74c283622f223625acb2d2 (patch) | |
tree | c39a5ffd32c13ba1379150d2fb001b18febe0b96 | |
parent | 9719a38d39bd5b70947eca50816a9719adeda5c6 (diff) | |
download | FreeBSD-src-a7ca300f12a749e66f74c283622f223625acb2d2.zip FreeBSD-src-a7ca300f12a749e66f74c283622f223625acb2d2.tar.gz |
Revert part of the r235740 which changed separate allocation of the
string buffer for each linelist l_line into one large string. Since
linelists parsed out during the previous passes store the pointers to
previously allocated l_lines, the reallocation caused undefined
behaviour on accessing the buffers, and quite deterministic fault on
freeing them (in mountd(8) startup).
This fixes reading of netgroup(5) file which contains more then one
netgroup.
Discussed with: ghelmer
MFC after: 3 days
-rw-r--r-- | lib/libc/gen/getnetgrent.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 933a7d3..f9dfd7b 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -538,7 +538,7 @@ parse_netgrp(const char *group) static struct linelist * read_for_group(const char *group) { - char *pos, *spos, *linep; + char *linep, *olinep, *pos, *spos; int len, olen; int cont; struct linelist *lp; @@ -615,15 +615,20 @@ read_for_group(const char *group) } else cont = 0; if (len > 0) { - linep = reallocf(linep, olen + len + 1); + linep = malloc(olen + len + 1); if (linep == NULL) { free(lp->l_groupname); free(lp); return (NULL); } + if (olen > 0) { + bcopy(olinep, linep, olen); + free(olinep); + } bcopy(pos, linep + olen, len); olen += len; *(linep + olen) = '\0'; + olinep = linep; } if (cont) { if (fgets(line, LINSIZ, netf)) { |