Avoid potentially undefined behavior.

Found by PVS Studio.
This commit is contained in:
Todd C. Miller
2018-10-16 12:50:43 -06:00
parent e1a402f1d6
commit 25a58ba1ca

View File

@@ -274,7 +274,8 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto done;
}
memcpy(++NewArgv, argv, argc * sizeof(char *));
NewArgv++; /* reserve an extra slot for --login */
memcpy(NewArgv, argv, argc * sizeof(char *));
NewArgv[NewArgc] = NULL;
if (ISSET(sudo_mode, MODE_LOGIN_SHELL) && runas_pw != NULL) {
NewArgv[0] = strdup(runas_pw->pw_shell);