svn commit: r190661 - head/lib/libc/gen
Xin LI
delphij at FreeBSD.org
Thu Apr 2 15:17:05 PDT 2009
Author: delphij
Date: Thu Apr 2 22:17:02 2009
New Revision: 190661
URL: http://svn.freebsd.org/changeset/base/190661
Log:
Properly handle malloc() failures.
PR: bin/83338
Modified:
head/lib/libc/gen/getcap.c
Modified: head/lib/libc/gen/getcap.c
==============================================================================
--- head/lib/libc/gen/getcap.c Thu Apr 2 22:04:44 2009 (r190660)
+++ head/lib/libc/gen/getcap.c Thu Apr 2 22:17:02 2009 (r190661)
@@ -189,7 +189,7 @@ getent(char **cap, u_int *len, char **db
{
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];
@@ -251,14 +251,16 @@ getent(char **cap, u_int *len, char **db
return (retval);
}
/* save the data; close frees it */
- clen = strlen(record);
- cbuf = malloc(clen + 1);
- memcpy(cbuf, record, clen + 1);
+ cbuf = strdup(record);
if (capdbp->close(capdbp) < 0) {
free(cbuf);
return (-2);
}
- *len = clen;
+ if (cbuf == NULL) {
+ errno = ENOMEM;
+ return (-2);
+ }
+ *len = strlen(record);
*cap = cbuf;
return (retval);
} else {
More information about the svn-src-all
mailing list