diff options
author | maxim <maxim@FreeBSD.org> | 2006-06-01 15:45:06 +0000 |
---|---|---|
committer | maxim <maxim@FreeBSD.org> | 2006-06-01 15:45:06 +0000 |
commit | b479e3f6b68bf41abe3b135fc3d7515398271236 (patch) | |
tree | ca8df75d120bf02daf6523b5cc7e82759f440974 /lib | |
parent | 65422bb62220eaa28b25a6a863563b85acd3df50 (diff) | |
download | FreeBSD-src-b479e3f6b68bf41abe3b135fc3d7515398271236.zip FreeBSD-src-b479e3f6b68bf41abe3b135fc3d7515398271236.tar.gz |
o Record a file offset for a last successfully parsed group file line.
If the initial buffer size (1KB) for the given group line is not big
enough, reset the offset. It helps to do not miss this line when
getrg() reallocates the larger buffer and tries to parse the line again.
PR: bin/52433, kern/55031, bin/83696, misc/97640, misc/98111
Submitted by: bsw71@mail.ru, Philip M. Gollucci, Justin Erenkrantz
Glanced at: nectar
MFC after: 1 month
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getgrent.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index d9ea5bd..511eddd 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -721,6 +721,7 @@ files_group(void *retval, void *mdata, va_list ap) gid_t gid; char *buffer; size_t bufsize, linesize; + off_t pos; int rv, stayopen, *errnop; name = NULL; @@ -757,6 +758,7 @@ files_group(void *retval, void *mdata, va_list ap) stayopen = st->stayopen; } rv = NS_NOTFOUND; + pos = ftello(st->fp); while ((line = fgetln(st->fp, &linesize)) != NULL) { if (line[linesize-1] == '\n') linesize--; @@ -768,10 +770,12 @@ files_group(void *retval, void *mdata, va_list ap) * pointer for the member list terminator. */ if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) { + fseeko(st->fp, pos, SEEK_SET); *errnop = ERANGE; rv = NS_RETURN; break; } + pos = ftello(st->fp); memcpy(buffer, line, linesize); buffer[linesize] = '\0'; rv = __gr_parse_entry(buffer, linesize, grp, @@ -1183,6 +1187,7 @@ compat_group(void *retval, void *mdata, va_list ap) char *buffer, *p; void *discard; size_t bufsize, linesize; + off_t pos; int rv, stayopen, *errnop; #define set_lookup_type(x, y) do { \ @@ -1286,6 +1291,7 @@ docompat: break; } rv = NS_NOTFOUND; + pos = ftello(st->fp); while ((line = fgetln(st->fp, &linesize)) != NULL) { if (line[linesize-1] == '\n') linesize--; @@ -1316,10 +1322,12 @@ docompat: * pointer for the member list terminator. */ if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) { + fseeko(st->fp, pos, SEEK_SET); *errnop = ERANGE; rv = NS_RETURN; break; } + pos = ftello(st->fp); memcpy(buffer, line, linesize); buffer[linesize] = '\0'; rv = __gr_parse_entry(buffer, linesize, grp, |