svn commit: r283809 - head/usr.sbin/pw

Baptiste Daroussin bapt at FreeBSD.org
Sun May 31 10:02:02 UTC 2015


Author: bapt
Date: Sun May 31 10:02:01 2015
New Revision: 283809
URL: https://svnweb.freebsd.org/changeset/base/283809

Log:
  Use asprintf instead of malloc + snprintf and test the memory allocation

Modified:
  head/usr.sbin/pw/pw.c

Modified: head/usr.sbin/pw/pw.c
==============================================================================
--- head/usr.sbin/pw/pw.c	Sun May 31 09:12:46 2015	(r283808)
+++ head/usr.sbin/pw/pw.c	Sun May 31 10:02:01 2015	(r283809)
@@ -221,8 +221,9 @@ main(int argc, char *argv[])
 		char * etcpath = getarg(&arglist, 'V')->val;
 		if (*etcpath) {
 			if (config == NULL) {	/* Only override config location if -C not specified */
-				config = malloc(MAXPATHLEN);
-				snprintf(config, MAXPATHLEN, "%s/pw.conf", etcpath);
+				asprintf(&config, "%s/pw.conf", etcpath);
+				if (config == NULL)
+					 errx(EX_OSERR, "out of memory");
 			}
 			memcpy(&PWF, &VPWF, sizeof PWF);
 			setpwdir(etcpath);


More information about the svn-src-all mailing list