Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 May 2009 21:52:01 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r192999 - in stable/7/lib/libc: . gen string
Message-ID:  <200905282152.n4SLq1ex050970@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905282152.n4SLq1ex050970>