svn commit: r192999 - in stable/7/lib/libc: . gen string

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


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

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

Modified:
  stable/7/lib/libc/   (props changed)
  stable/7/lib/libc/gen/getcap.c
  stable/7/lib/libc/string/ffsll.c   (props changed)
  stable/7/lib/libc/string/flsll.c   (props changed)

Modified: stable/7/lib/libc/gen/getcap.c
==============================================================================
--- stable/7/lib/libc/gen/getcap.c	Thu May 28 21:41:01 2009	(r192998)
+++ stable/7/lib/libc/gen/getcap.c	Thu May 28 21:52:00 2009	(r192999)
@@ -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(cbuf);
 				*cap = cbuf;
 				return (retval);
 			} else {


More information about the svn-src-all mailing list