r23760: Untangle use of strrchr_m and strequal and add some checks
authorMichael Adam <obnox@samba.org>
Mon, 9 Jul 2007 09:35:03 +0000 (09:35 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:23:53 +0000 (12:23 -0500)
for the validity of the given registry key name.

Michael
(This used to be commit 4b4ba7724ee77a93e32cd7f3c5884d965fe9bcaa)

source3/utils/net_conf.c

index 49905413840d590b6c37fde08a994a6236f533dd..61bcb60aaf1008006254d29e77baa59aac2f0902 100644 (file)
@@ -151,6 +151,7 @@ static WERROR reg_setvalue_internal(struct registry_key *key,
 {
        struct registry_value val;
        WERROR werr = WERR_OK;
+       char *subkeyname;
 
        ZERO_STRUCT(val);
 
@@ -171,12 +172,20 @@ static WERROR reg_setvalue_internal(struct registry_key *key,
                goto done;
        }
 
-       if (!strequal(strrchr_m(key->key->name, '\\')+1, GLOBAL_NAME) &&
+       subkeyname = strrchr_m(key->key->name, '\\');
+       if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
+               d_fprintf(stderr, "Invalid registry key '%s' given as "
+                         "smbconf section.\n", key->key->name);
+               werr = WERR_INVALID_PARAM;
+               goto done;
+       }
+       subkeyname++;
+       if (!strequal(subkeyname, GLOBAL_NAME) &&
            lp_parameter_is_global(valname))
        {
                d_fprintf(stderr, "Global paramter '%s' not allowed in "
                          "service definition ('%s').\n", valname,
-                         strrchr_m(key->key->name, '\\')+1);
+                         subkeyname);
                werr = WERR_INVALID_PARAM;
                goto done;
        }