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);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to