Date: Mon, 20 Nov 2000 12:20:08 -0800 (PST) From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> To: freebsd-bugs@FreeBSD.org Subject: bin/22965: [PATCH] fix for minor bug in libc/gen/getcap.c Message-ID: <200011202020.MAA28872@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/22965; it has been noted by GNATS. From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> 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 -*- <<On Sun, 19 Nov 2000 18:51:26 -0500 (EST), Garance A Drosehn <gad@freefour.acs.rpi.edu> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011202020.MAA28872>