]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
cmdline:burn: do not retain false memories
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 27 Jun 2024 03:20:27 +0000 (15:20 +1200)
committerJule Anger <janger@samba.org>
Tue, 23 Jul 2024 07:32:13 +0000 (07:32 +0000)
If argv contains a secret option without an '=' (or in the case of
"-U", the username is separated by space), we will get to the
`if (strlen(p) == ulen) { continue; }` without resetting the found
and is_user variables. This *sometimes* has the right effect, because
the next string in argv ought to contain the secret.

But in a case like {"--password", "1234567890"}, where the secret
string is the same length as the option, we *again* take that branch
and the password is not redacted, though the argument after it will be
unless it is also of the same length.

If we always set the flags at the start we avoid this. This makes
things worse in the short term for secrets that are not the same
length as their options, but we'll get to that in another commit soon.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
(cherry picked from commit 2f6020cf3dadf484251701040e09a10fba2f644e)

lib/cmdline/cmdline.c

index aaaff4469790f83a47d2d36ab24dca4a992db1f3..3e0545e7b898f098b7c798f6e8a288f55ec90740 100644 (file)
@@ -150,6 +150,9 @@ bool samba_cmdline_burn(int argc, char *argv[])
                        return false;
                }
 
+               found = false;
+               is_user = false;
+
                /*
                 * Take care that this list must be in longest-match
                 * first order
@@ -192,8 +195,6 @@ bool samba_cmdline_burn(int argc, char *argv[])
                        }
 
                        memset_s(p, strlen(p), '\0', strlen(p));
-                       found = false;
-                       is_user = false;
                        burnt = true;
                }
        }