]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:passdb: Zero memory in pdb_set_plaintext_passwd()
authorPavel Filipenský <pfilipensky@samba.org>
Mon, 8 Aug 2022 16:23:40 +0000 (18:23 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 26 Aug 2022 07:59:32 +0000 (07:59 +0000)
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/passdb/pdb_get_set.c

index 13bea8d40a67b0d7c4634d95b3226669c1902785..7015fce9149466b5d6ff96bafc1a0c02e0b58c9d 100644 (file)
@@ -1001,6 +1001,7 @@ bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
 {
        uchar new_lanman_p16[LM_HASH_LEN];
        uchar new_nt_p16[NT_HASH_LEN];
+       bool ok;
 
        if (!plaintext)
                return False;
@@ -1008,8 +1009,10 @@ bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
        /* Calculate the MD4 hash (NT compatible) of the password */
        E_md4hash(plaintext, new_nt_p16);
 
-       if (!pdb_set_nt_passwd (sampass, new_nt_p16, PDB_CHANGED))
+       if (!pdb_set_nt_passwd (sampass, new_nt_p16, PDB_CHANGED)) {
+               ZERO_STRUCT(new_nt_p16);
                return False;
+       }
 
        if (!E_deshash(plaintext, new_lanman_p16)) {
                /* E_deshash returns false for 'long' passwords (> 14
@@ -1017,21 +1020,33 @@ bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
                   does not store a LM hash for these passwords (which
                   would reduce the effective password length to 14 */
 
-               if (!pdb_set_lanman_passwd (sampass, NULL, PDB_CHANGED))
+               if (!pdb_set_lanman_passwd (sampass, NULL, PDB_CHANGED)) {
+                       ZERO_STRUCT(new_nt_p16);
+                       ZERO_STRUCT(new_lanman_p16);
                        return False;
+               }
        } else {
-               if (!pdb_set_lanman_passwd (sampass, new_lanman_p16, PDB_CHANGED))
+               if (!pdb_set_lanman_passwd (sampass, new_lanman_p16, PDB_CHANGED)) {
+                       ZERO_STRUCT(new_nt_p16);
+                       ZERO_STRUCT(new_lanman_p16);
                        return False;
+               }
        }
+       ZERO_STRUCT(new_lanman_p16);
 
-       if (!pdb_set_plaintext_pw_only (sampass, plaintext, PDB_CHANGED))
+       if (!pdb_set_plaintext_pw_only (sampass, plaintext, PDB_CHANGED)) {
+               ZERO_STRUCT(new_nt_p16);
                return False;
+       }
 
-       if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED))
+       if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED)) {
+               ZERO_STRUCT(new_nt_p16);
                return False;
+       }
 
-
-       return pdb_update_history(sampass, new_nt_p16);
+       ok = pdb_update_history(sampass, new_nt_p16);
+       ZERO_STRUCT(new_nt_p16);
+       return ok;
 }
 
 /*********************************************************************