From 3af58faa587f263481899bbe5a258c74be6038c0 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 31 May 2015 10:02:01 +0000 Subject: Use asprintf instead of malloc + snprintf and test the memory allocation --- pw/pw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index ff48db7..0c41f03 100644 --- a/pw/pw.c +++ b/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); -- cgit v1.2.3-56-ge451