From owner-freebsd-bugs Mon Nov 20 18:30: 6 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4B13437B4CF for ; Mon, 20 Nov 2000 18:30:03 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id SAA91302; Mon, 20 Nov 2000 18:30:03 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Mon, 20 Nov 2000 18:30:03 -0800 (PST) Message-Id: <200011210230.SAA91302@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Garance A Drosehn Subject: Re: bin/22965: [PATCH] fix for minor bug in libc/gen/getcap.c Reply-To: Garance A Drosehn Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/22965; it has been noted by GNATS. From: Garance A Drosehn To: Garrett Wollman Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/22965: [PATCH] fix for minor bug in libc/gen/getcap.c Date: Mon, 20 Nov 2000 21:19:44 -0500 Here is an improved version of the patch. Note that I have tested this on a private copy of 'getcap.c' that I use in a project of mine (which is compiled on multiple platforms), so I know it compiles and it works fine in that project. However, I haven't figured out how to build a new libc on freebsd, so I can't say I've tested this patch installed into freebsd's libc... Index: getcap.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/getcap.c,v retrieving revision 1.12 diff -u -r1.12 getcap.c --- getcap.c 2000/05/21 02:55:09 1.12 +++ getcap.c 2000/11/21 02:14:10 @@ -647,7 +647,7 @@ char **db_array; { size_t len; - int status, i, done; + int done, hadreaderr, i, savederrno, status; char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; u_int dummy; @@ -665,9 +665,14 @@ } else { line = fgetln(pfp, &len); if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; return (-1); } else { if (*++dbp == NULL) { @@ -724,9 +729,18 @@ } else { /* name field extends beyond the line */ line = fgetln(pfp, &len); if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); + /* Name extends beyond the EOF! */ + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; + return (-1); + } else { + cgetclose(); return (-1); } } else --- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer (MIME & NeXTmail capable) Rensselaer Polytechnic Institute; Troy NY USA To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message