net: change split_hive_key() to properly allocate subkeyname
authorMichael Adam <obnox@samba.org>
Fri, 4 Apr 2008 15:24:53 +0000 (17:24 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 4 Apr 2008 15:24:53 +0000 (17:24 +0200)
instead of returning a pointer into another string.

Michael
(This used to be commit 68d08ecf92be3444b759300237b2b7cf5238d022)

source3/utils/net_registry.c
source3/utils/net_registry_util.c
source3/utils/net_registry_util.h
source3/utils/net_rpc_registry.c

index f21a1603cf3ee55ab975c0f53c04a654e618859d..8a45dec21caf92b7a22a3e6901db9ad16eaade32 100644 (file)
@@ -41,7 +41,7 @@ static WERROR open_hive(TALLOC_CTX *ctx, const char *path,
        WERROR werr;
        NT_USER_TOKEN *token = NULL;
        char *hivename = NULL;
-       const char *tmp_subkeyname = NULL;
+       char *tmp_subkeyname = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
        if ((hive == NULL) || (subkeyname == NULL)) {
index b1d0c7765c8ec19a8d70a9b1cafb648bb6550c96..948f8b6153f38417e99812a09133fbbb9ef4e5ba 100644 (file)
@@ -72,9 +72,10 @@ void print_registry_value(const char *valname,
  *  - strip trailing '\\' chars
  */
 WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
-                     const char **subkeyname)
+                     char **subkeyname)
 {
        char *p;
+       const char *tmp_subkeyname;
 
        if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
                return WERR_INVALID_PARAM;
@@ -100,10 +101,14 @@ WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
 
        if ((p == NULL) || (*p == '\0')) {
                /* just the hive - no subkey given */
-               *subkeyname = "";
+               tmp_subkeyname = "";
        } else {
                *p = '\0';
-               *subkeyname = p+1;
+               tmp_subkeyname = p+1;
+       }
+       *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
+       if (*subkeyname == NULL) {
+               return WERR_NOMEM;
        }
 
        return WERR_OK;
index 5438f39946983e9444c48cb01c035248a9b63f61..13ec6ebfcdd23535a7c4387d70a82580d3713782 100644 (file)
@@ -34,6 +34,6 @@ void print_registry_value(const char *valname,
  *  - strip trailing '\\' chars
  */
 WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
-                     const char **subkeyname);
+                     char **subkeyname);
 
 #endif
index 0d1f0688628557d9bf14613f6f2202d7bb34a043..92aaf06411332aac1811fa511d1e28c2b28a6f65 100644 (file)
@@ -28,7 +28,7 @@ static bool reg_hive_key(TALLOC_CTX *ctx, const char *fullname,
 {
        WERROR werr;
        char *hivename = NULL;
-       const char *tmp_keyname = NULL;
+       char *tmp_keyname = NULL;
        bool ret = false;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();