diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2011-10-14 16:33:54 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2011-10-14 16:33:54 +0000 |
commit | e0ceabf7b12be93407135f1967c540b592d8e3d0 (patch) | |
tree | c7962fc6aa54957513398d9289c287b6f5e3521c /lib/libc | |
parent | 497ff727d1e9d4a929d85a98b17d08e0f26da87e (diff) |
Fix toprec handling in cgetnext(). OK otto@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getcap.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index dee764c5a82..b2d0d616cd3 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcap.c,v 1.29 2011/07/10 13:31:02 millert Exp $ */ +/* $OpenBSD: getcap.c,v 1.30 2011/10/14 16:33:53 millert Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -658,11 +658,12 @@ cgetclose(void) int cgetnext(char **cap, char **db_array) { - size_t len; + size_t len, otopreclen = topreclen; int c, serrno, status = -1; char buf[BUFSIZ], nbuf[BSIZE]; char *b_end, *bp, *r_end, *rp; char *record = NULL; + char *otoprec = toprec; u_int dummy; off_t pos; @@ -677,6 +678,7 @@ cgetnext(char **cap, char **db_array) */ if (toprec && !gottoprec) { gottoprec = 1; + record = toprec; goto lookup; } @@ -770,7 +772,6 @@ cgetnext(char **cap, char **db_array) fseeko(pfp, (off_t)(bp - b_end), SEEK_CUR); toprec = record; topreclen = rp - record; - gottoprec = 1; break; } } @@ -787,7 +788,11 @@ lookup: fseeko(pfp, pos, SEEK_SET); done: serrno = errno; - free(record); + if (toprec != otoprec) { + toprec = otoprec; + topreclen = otopreclen; + free(record); + } if (status <= 0) (void)cgetclose(); errno = serrno; |