Date: Tue, 12 Jul 2005 18:40:15 GMT From: Dan Lukes <dan@obluda.cz> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/83338: [ PATCH ] libc's getent() don't check for malloc failure Message-ID: <200507121840.j6CIeFsd070088@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/83338; it has been noted by GNATS. From: Dan Lukes <dan@obluda.cz> To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/83338: [ PATCH ] libc's getent() don't check for malloc failure Date: Tue, 12 Jul 2005 20:35:15 +0200 This is a multi-part message in MIME format. --------------070009010608060701060504 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit I'm sorry, the incorrect patch file has been attached. The correct one follows. Dan -- Dan Lukes SISAL MFF UK AKA: dan@obluda.cz, dan@freebsd.cz,dan@kolej.mff.cuni.cz --------------070009010608060701060504 Content-Type: text/plain; name="x" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="x" --- lib/libc/gen/getcap.c.ORIG Thu Jan 2 20:26:24 2003 +++ lib/libc/gen/getcap.c Tue Jul 12 20:30:53 2005 @@ -193,7 +193,7 @@ { DB *capdbp; char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval, clen; + int myfd, eof, foundit, retval; char *record, *cbuf; int tc_not_resolved; char pbuf[_POSIX_PATH_MAX]; @@ -255,14 +255,16 @@ return (retval); } /* save the data; close frees it */ - clen = strlen(record); - cbuf = malloc(clen + 1); - memcpy(cbuf, record, clen + 1); + if ((cbuf = strdup(record)) == NULL) { + capdbp->close(capdbp); + errno = ENOMEM; + return (-2); + } if (capdbp->close(capdbp) < 0) { free(cbuf); return (-2); } - *len = clen; + *len = strlen(cbuf); *cap = cbuf; return (retval); } else { --------------070009010608060701060504--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507121840.j6CIeFsd070088>