]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Safeguards for getpwuid
authorVolker Lendecke <vl@samba.org>
Thu, 3 Feb 2022 12:20:11 +0000 (13:20 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 11 Feb 2022 20:54:37 +0000 (20:54 +0000)
Attempt to fix

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14900

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/passdb/pdb_interface.c

index 3c4499a4459dd7136987c428a8980751864f5c2e..b83cef1de373e0b7f4659c4453d16997de406d6d 100644 (file)
@@ -1402,6 +1402,7 @@ static bool pdb_default_uid_to_sid(struct pdb_methods *methods, uid_t uid,
 {
        struct samu *sampw = NULL;
        struct passwd *unix_pw;
+       fstring pw_name = { 0 };
        bool ret;
 
        unix_pw = getpwuid( uid );
@@ -1412,14 +1413,23 @@ static bool pdb_default_uid_to_sid(struct pdb_methods *methods, uid_t uid,
                return False;
        }
 
+       if (unix_pw->pw_name == NULL) {
+               DBG_DEBUG("No pw_name for uid %d\n", (int)uid);
+               return false;
+       }
+
+       /*
+        * Make a copy, "unix_pw" might go away soon.
+        */
+       fstrcpy(pw_name, unix_pw->pw_name);
+
        if ( !(sampw = samu_new( NULL )) ) {
                DEBUG(0,("pdb_default_uid_to_sid: samu_new() failed!\n"));
                return False;
        }
 
        become_root();
-       ret = NT_STATUS_IS_OK(
-               methods->getsampwnam(methods, sampw, unix_pw->pw_name ));
+       ret = NT_STATUS_IS_OK(methods->getsampwnam(methods, sampw, pw_name));
        unbecome_root();
 
        if (!ret) {