bin/83338: [ PATCH ] libc's getent() don't check for malloc
failure
Dan Lukes
dan at obluda.cz
Tue Jul 12 18:40:16 GMT 2005
The following reply was made to PR bin/83338; it has been noted by GNATS.
From: Dan Lukes <dan at obluda.cz>
To: bug-followup at 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 at obluda.cz, dan at freebsd.cz,dan at 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--
More information about the freebsd-bugs
mailing list