diff options
author | bapt <bapt@FreeBSD.org> | 2015-05-31 10:02:01 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-05-31 10:02:01 +0000 |
commit | 23c55809b120274eefd632486dc1f7c071a3ad4b (patch) | |
tree | b0f69a64157cd61ca5208c6c523524a5dd92bb36 /usr.sbin/pw/pw.c | |
parent | f8cf17bf1f7d3fda2c17e8921910ba8baa3bfc75 (diff) | |
download | FreeBSD-src-23c55809b120274eefd632486dc1f7c071a3ad4b.zip FreeBSD-src-23c55809b120274eefd632486dc1f7c071a3ad4b.tar.gz |
Use asprintf instead of malloc + snprintf and test the memory allocation
Diffstat (limited to 'usr.sbin/pw/pw.c')
-rw-r--r-- | usr.sbin/pw/pw.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index ff48db7..0c41f03 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); |