Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 May 2015 10:02:02 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r283809 - head/usr.sbin/pw
Message-ID:  <201505311002.t4VA22fM034662@svn.freebsd.org>

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



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