From 23c55809b120274eefd632486dc1f7c071a3ad4b Mon Sep 17 00:00:00 2001 From: bapt Date: Sun, 31 May 2015 10:02:01 +0000 Subject: [PATCH] Use asprintf instead of malloc + snprintf and test the memory allocation --- usr.sbin/pw/pw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index ff48db7af169..0c41f03e565c 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -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);