svn commit: r193000 - in stable/6/lib/libc: . gen inet sys

Xin LI delphij at FreeBSD.org
Thu May 28 21:52:38 UTC 2009


Author: delphij
Date: Thu May 28 21:52:36 2009
New Revision: 193000
URL: http://svn.freebsd.org/changeset/base/193000

Log:
  Merge r192129+r190661:
  
  Properly handle malloc() failures.
  
  PR:	bin/83338

Modified:
  stable/6/lib/libc/   (props changed)
  stable/6/lib/libc/gen/getcap.c
  stable/6/lib/libc/inet/inet_net_pton.c   (props changed)
  stable/6/lib/libc/sys/   (props changed)

Modified: stable/6/lib/libc/gen/getcap.c
==============================================================================
--- stable/6/lib/libc/gen/getcap.c	Thu May 28 21:52:00 2009	(r192999)
+++ stable/6/lib/libc/gen/getcap.c	Thu May 28 21:52:36 2009	(r193000)
@@ -193,7 +193,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];
@@ -255,14 +255,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(cbuf);
 				*cap = cbuf;
 				return (retval);
 			} else {


More information about the svn-src-all mailing list