Replace malloc(3) + strcpy(3) + strcat(3) by asprintf(3)

This commit is contained in:
Baptiste Daroussin 2015-05-09 19:12:16 +00:00
parent a546448b8d
commit b2298745ac

View File

@ -363,11 +363,9 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
if (mode == M_LOCK) {
if (strncmp(pwd->pw_passwd, locked_str, sizeof(locked_str)-1) == 0)
errx(EX_DATAERR, "user '%s' is already locked", pwd->pw_name);
passtmp = malloc(strlen(pwd->pw_passwd) + sizeof(locked_str));
asprintf(&passtmp, "%s%s", locked_str, pwd->pw_passwd);
if (passtmp == NULL) /* disaster */
errx(EX_UNAVAILABLE, "out of memory");
strcpy(passtmp, locked_str);
strcat(passtmp, pwd->pw_passwd);
pwd->pw_passwd = passtmp;
edited = 1;
} else if (mode == M_UNLOCK) {