From owner-freebsd-bugs Mon Nov 20 12:20:11 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 2967F37B479 for ; Mon, 20 Nov 2000 12:20:08 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id MAA28872; Mon, 20 Nov 2000 12:20:08 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Mon, 20 Nov 2000 12:20:08 -0800 (PST) Message-Id: <200011202020.MAA28872@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Garrett Wollman Subject: bin/22965: [PATCH] fix for minor bug in libc/gen/getcap.c Reply-To: Garrett Wollman 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: Garrett Wollman To: gad@eclipse.acs.rpi.edu Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/22965: [PATCH] fix for minor bug in libc/gen/getcap.c Date: Mon, 20 Nov 2000 15:16:35 -0500 (EST) -*- Mode: BDE -*- < said: > -static size_t topreclen; /* toprec length */ > -static char *toprec; /* Additional record specified by cgetset() */ > -static int gottoprec; /* Flag indicating retrieval of toprecord */ > +static size_t topreclen = 0; /* toprec length */ > +static char *toprec = NULL; /* Additional record specified by cgetset() */ > +static int gottoprec = 0; /* Flag indicating retrieval of toprecord */ These changes are erroneous, and have the sole effect of moving these variables from .bss, where they occupy only virtual space, to .data where they waste space on disk. > - (void)fclose(pfp); > - if (ferror(pfp)) { > + fcloseres = fclose(pfp); > + pfp = NULL; > + if (fcloseres != 0) { This also appears to be the Wrong Thing. The intent of the code seems to be to detect whether *reading* failed. As implemented in FreeBSD, fclose() of a read-only file can never fail. The correct emendation would be: haderror = ferror(pfp); fclose(pfp); if (haderror) { Even thus, this still could clobber errno (although fgetln() does not necessarily set it usefully); an even better version might be: int savederrno, haderror; savederrno = errno; /* ... */ haderror = ferror(pfp); if (haderror) savederrno = errno; fclose(pfp); if (haderror) { cgetclose(); errno = savederrno; return (-1); } -GAWollman -- Garrett A. Wollman | O Siem / We are all family / O Siem / We're all the same wollman@lcs.mit.edu | O Siem / The fires of freedom Opinions not those of| Dance in the burning flame MIT, LCS, CRS, or NSA| - Susan Aglukark and Chad Irschick To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message