diff options
author | delphij <delphij@FreeBSD.org> | 2009-04-02 22:17:02 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2009-04-02 22:17:02 +0000 |
commit | bd34ecb2f69373dcb25dfef228f906aacb4ff26e (patch) | |
tree | 63200327c8f5b860b3004a0b2545de28509bd145 /lib/libc/gen | |
parent | 6731e932f675415e0190d3fb4897f920b9c907f7 (diff) | |
download | FreeBSD-src-bd34ecb2f69373dcb25dfef228f906aacb4ff26e.zip FreeBSD-src-bd34ecb2f69373dcb25dfef228f906aacb4ff26e.tar.gz |
Properly handle malloc() failures.
PR: bin/83338
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/getcap.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index 0f0bb20..d0e4a7b 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -189,7 +189,7 @@ getent(char **cap, u_int *len, char **db_array, int fd, const char *name, { 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_array, int fd, const char *name, 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 { |