From 15ca51e3e2a31efc275b616106244d8ec3f8f773 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 29 Oct 2007 19:25:45 +0000 Subject: appletlib.c: make it actally follow _BB_SUID_ALWAYS rules adduser: implement -S and code shrink / fix uid selection *: sanitize getspnam_r use text data bss dec hex filename 777042 974 9676 787692 c04ec busybox_old 776883 974 9676 787533 c044d busybox_unstripped --- loginutils/sulogin.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'loginutils/sulogin.c') diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index f633fbb..f1545b7 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -44,7 +44,6 @@ int sulogin_main(int argc, char **argv) /* Using _r function to avoid pulling in static buffers */ char buffer[256]; struct spwd spw; - struct spwd *result; #endif logmode = LOGMODE_BOTH; @@ -83,10 +82,16 @@ int sulogin_main(int argc, char **argv) } #if ENABLE_FEATURE_SHADOWPASSWDS - if (getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result)) { - goto auth_error; + { + /* getspnam_r may return 0 yet set result to NULL. + * At least glibc 2.4 does this. Be extra paranoid here. */ + struct spwd *result = NULL; + int r = getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result); + if (r || !result) { + goto auth_error; + } + pwd->pw_passwd = result->sp_pwdp; } - pwd->pw_passwd = spw.sp_pwdp; #endif while (1) { -- cgit v1.1