mirror of git://git.suckless.org/ubase
Use a compound literal instead of malloc() in su(1)
This commit is contained in:
parent
dac38406c2
commit
f7fdd58972
8
su.c
8
su.c
|
@ -20,7 +20,7 @@ int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *usr, *pass, *cryptpass;
|
char *usr, *pass, *cryptpass;
|
||||||
char **newargv;
|
char * const *newargv;
|
||||||
struct spwd *spw;
|
struct spwd *spw;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
@ -83,11 +83,7 @@ main(int argc, char **argv)
|
||||||
if (setuid(pw->pw_uid) < 0)
|
if (setuid(pw->pw_uid) < 0)
|
||||||
eprintf("setuid:");
|
eprintf("setuid:");
|
||||||
|
|
||||||
newargv = malloc(2 * sizeof(char *));
|
newargv = (char *const[]){pw->pw_shell, NULL};
|
||||||
if (!newargv)
|
|
||||||
eprintf("malloc:");
|
|
||||||
newargv[0] = pw->pw_shell;
|
|
||||||
newargv[1] = NULL;
|
|
||||||
setenv("HOME", pw->pw_dir, 1);
|
setenv("HOME", pw->pw_dir, 1);
|
||||||
execve(pw->pw_shell, newargv, environ);
|
execve(pw->pw_shell, newargv, environ);
|
||||||
return (errno == ENOENT) ? 127 : 126;
|
return (errno == ENOENT) ? 127 : 126;
|
||||||
|
|
Loading…
Reference in New Issue