Use asprintf instead of malloc + snprintf and test the memory allocation

This commit is contained in:
Baptiste Daroussin 2015-05-31 10:02:01 +00:00
parent 027cfc25a9
commit 197419154e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=283809

View File

@ -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);