s4-libregistry: Fix path check and improve while loops.
authorAndreas Schneider <asn@samba.org>
Mon, 25 Feb 2013 14:13:19 +0000 (15:13 +0100)
committerDavid Disseldorp <ddiss@suse.de>
Tue, 5 Mar 2013 22:30:03 +0000 (23:30 +0100)
Reviewed-by: David Disseldorp <ddiss@samba.org>
source4/lib/registry/local.c

index 98791743aec5cfceed69ac601c9976fbc46478f3..79c398b68a90f7352e309df77abd533a5586fdfe 100644 (file)
@@ -80,7 +80,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
        const char **elements = NULL;
        int el;
 
-       if (path == NULL) {
+       if (path == NULL || path[0] == '\0') {
                return WERR_INVALID_PARAM;
        }
 
@@ -103,7 +103,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
                el = 0;
        }
 
-       while (curbegin != NULL && *curbegin) {
+       do {
                if (curend != NULL)
                        *curend = '\0';
                elements = talloc_realloc(mem_ctx, elements, const char *, el+2);
@@ -124,7 +124,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
                        break;
                curbegin = curend + 1;
                curend = strchr(curbegin, '\\');
-       }
+       } while (curbegin != NULL && curbegin[0] != '\0');
        talloc_free(orig);
 
        *result = reg_import_hive_key(local_parent->global.context, curkey,
@@ -184,7 +184,7 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx,
        const char **elements = NULL;
        int el;
 
-       if (path == NULL) {
+       if (path == NULL || path[0] == '\0') {
                return WERR_INVALID_PARAM;
        }
 
@@ -207,7 +207,7 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx,
                el = 0;
        }
 
-       while (curbegin != NULL && *curbegin) {
+       do {
                if (curend != NULL)
                        *curend = '\0';
                elements = talloc_realloc(mem_ctx, elements, const char *, el+2);
@@ -233,7 +233,7 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx,
                        break;
                curbegin = curend + 1;
                curend = strchr(curbegin, '\\');
-       }
+       } while (curbegin != NULL && curbegin[0] != '\0');
        talloc_free(orig);
 
        *result = reg_import_hive_key(local_parent->global.context, curkey,