fix nasty expired pointer

master
Alessandro Mauri 4 years ago
parent 2e181319ed
commit 1594ec867b
  1. 12
      us.c

12
us.c

@ -102,12 +102,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "getpwid: %s\n", strerror(errno));
return errno;
}
char *my_name = strdup(my_pw->pw_name);
if (!my_name)
die("strdup:");
/* Authenticate, we will be root from now on */
if (authenticate(my_pw->pw_uid, 0))
exit(EXIT_FAILURE);
/* Get target user and group info */
t_pw = user_to_passwd(t_usr);
if (!t_pw)
@ -169,8 +171,11 @@ int main(int argc, char *argv[])
};
if (envflag) { /* clear env */
for (int i = 0; env_keep[i].name; i++)
for (int i = 0; env_keep[i].name; i++) {
env_keep[i].value = strdup(getenv(env_keep[i].name));
if (!env_keep[i].value)
die("strdup:");
}
environ = NULL; // in place of clearenv
}
@ -194,7 +199,8 @@ int main(int argc, char *argv[])
}
}
// do not override, we might be under more levels of 'us'
err = setenv("US_USER", my_pw->pw_name, 0);
err = setenv("US_USER", my_name, 0);
free(my_name);
errno = 0;
/* Set permissions */

Loading…
Cancel
Save