summaryrefslogtreecommitdiffstats
path: root/pw/pw.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-05-31 10:02:01 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-05-31 10:02:01 +0000
commit3af58faa587f263481899bbe5a258c74be6038c0 (patch)
tree04b4030cc05653f0c870142b9de8cd21d01c4063 /pw/pw.c
parentb76f48320c5b5f6d44afab6e67b2da6c8f77c08b (diff)
downloadpw-darwin-3af58faa587f263481899bbe5a258c74be6038c0.tar.gz
pw-darwin-3af58faa587f263481899bbe5a258c74be6038c0.tar.zst
pw-darwin-3af58faa587f263481899bbe5a258c74be6038c0.zip
Use asprintf instead of malloc + snprintf and test the memory allocation
Diffstat (limited to 'pw/pw.c')
-rw-r--r--pw/pw.c5
1 files changed, 3 insertions, 2 deletions
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);