]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
cmdline:burn: localise some variables
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 27 Jun 2024 04:33:16 +0000 (16:33 +1200)
committerJule Anger <janger@samba.org>
Tue, 23 Jul 2024 07:32:13 +0000 (07:32 +0000)
As this function increases in complexity, it helps to keep things close.

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 f5233ddf974f9649d8a12b151b6843412eab489c)

lib/cmdline/cmdline.c

index fa3bfefecedb5164c684736afbcebaebbd96b082..d20c606d5036477c66ed1f529b3d763be7f38ef9 100644 (file)
@@ -138,24 +138,22 @@ void samba_cmdline_set_machine_account_fn(
 bool samba_cmdline_burn(int argc, char *argv[])
 {
        bool burnt = false;
-       bool found = false;
-       bool is_user = false;
-       char *p = NULL;
        int i;
-       size_t ulen = 0;
 
        for (i = 0; i < argc; i++) {
+               bool found = false;
+               bool is_user = false;
+               size_t ulen = 0;
+               char *p = NULL;
+
                p = argv[i];
                if (p == NULL) {
                        return burnt;
                }
 
-               found = false;
-               is_user = false;
-
                /*
                 * Take care that this list must be in longest-match
-                * first order
+                * first order (e.g. --password2 before --password).
                 */
                if (strncmp(p, "-U", 2) == 0) {
                        ulen = 2;
@@ -177,8 +175,6 @@ bool samba_cmdline_burn(int argc, char *argv[])
                }
 
                if (found) {
-                       char *q = NULL;
-
                        if (strlen(p) == ulen) {
                                /*
                                 * The option string has no '=', so
@@ -209,7 +205,7 @@ bool samba_cmdline_burn(int argc, char *argv[])
                        }
 
                        if (is_user) {
-                               q = strchr_m(p, '%');
+                               char *q = strchr_m(p, '%');
                                if (q == NULL) {
                                        /* -U without '%' has no secret */
                                        continue;