Correct initializer - targetname[0] is access even when no 'u' option is given

This commit is contained in:
helmat 2022-09-14 10:00:06 +02:00 committed by GitHub
parent 9a4eb403de
commit f121a2e063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

2
doas.c
View file

@ -302,6 +302,7 @@ main(int argc, char **argv)
closefrom(STDERR_FILENO + 1);
uid = getuid();
targetname[0] = '\0';
while ((ch = getopt(argc, argv, "+a:C:nSsu:")) != -1) {
switch (ch) {
@ -320,7 +321,6 @@ main(int argc, char **argv)
exit(i != -1);
*/
case 'u':
targetname[0] = '\0';
if (strlcpy(targetname, optarg, sizeof(targetname)) >= sizeof(targetname))
errx(1, "pw_name too long");
if (parseuid(targetname, &target) != 0)