The branch, master has been updated via 12f42e3... s4:registry - "reg_import_hive_key" - change a "talloc_steal" into a "talloc_reference" via e246633... s4:registry - "patchfile" - add another "W_ERROR_HAVE_NO_MEMORY" macro call via 8046cbe... s4:registry - "local" - add also here more "W_ERROR_HAVE_NO_MEMORY" macro tests via e690c07... s4:registry - "util.c" - initialise "result" in "reg_key_add_abs" via 0c10703... s4:WINREG RPC - add also here a "W_ERROR_HAVE_NO_MEMORY" via e78289f... s4:registry - "samba.c" - add a "talloc_free" via dc17292... s4:registry - add more "W_ERROR_HAVE_NO_MEMORY" invocations (on talloc'ed stuff) via 9c3e624... s4:registry - "util" - remove "const" from "reg_abs_path" via 5f850af... s4:registry - adaptions for "add also a memory context argument for "reg_key_del_abs" via 5b6ad54... s4:registry - "util" - add also a memory context argument for "reg_key_del_abs" via 9d85929... s4:registry - "util" - make "reg_key_add_abs" consistent with "reg_key_del_abs" via 05d8882... s4:registry - "util" - fix up memory allocated data via 96bb09b... s4:registry - "dir.c" - fix up dynamic memory allocation operations via 43170da... s4:registry - adaptions for "add memory contexts for delete value/key functions" via 64f5138... s4:registry - registry.h - add memory contexts for delete value/key functions from e2c7e5c... tdb: Fix bug 7248, avoid the nanosleep dependency
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 12f42e35bcbb819cb742c28538b7cc67ac9d93cf Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 22:23:08 2010 +0100 s4:registry - "reg_import_hive_key" - change a "talloc_steal" into a "talloc_reference" Use a "talloc_reference" since the "hive" variable can continue to exist also after the destructed "struct local_key" object. It is also referenced by the "mountpoints" structure under the "ctx" object. commit e2466334a07062ca9c7160c8487386e1743d982a Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 22:01:31 2010 +0100 s4:registry - "patchfile" - add another "W_ERROR_HAVE_NO_MEMORY" macro call commit 8046cbe3c1b2a61081ef091398ec0ff2183e7a0d Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 21:46:39 2010 +0100 s4:registry - "local" - add also here more "W_ERROR_HAVE_NO_MEMORY" macro tests commit e690c0776fa4d3a475e9291c243be6141d54b4d4 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 21:34:54 2010 +0100 s4:registry - "util.c" - initialise "result" in "reg_key_add_abs" commit 0c10703c756117ad1a8c9e911157cd9ca81f0f70 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 20:14:51 2010 +0100 s4:WINREG RPC - add also here a "W_ERROR_HAVE_NO_MEMORY" commit e78289f167363f3617f7417f7e25de369ea22d7f Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 20:12:13 2010 +0100 s4:registry - "samba.c" - add a "talloc_free" commit dc17292f1a097d3abd8c391315b661034ab1914e Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 20:10:26 2010 +0100 s4:registry - add more "W_ERROR_HAVE_NO_MEMORY" invocations (on talloc'ed stuff) commit 9c3e6249fd984b823a77cab0514601d2a487920a Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:53:23 2010 +0100 s4:registry - "util" - remove "const" from "reg_abs_path" Here it's not really needed commit 5f850af84aec378780b5caeff9e795297654abcc Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:56:52 2010 +0100 s4:registry - adaptions for "add also a memory context argument for "reg_key_del_abs" commit 5b6ad54f43741c0c25b35e44cafe5fed352ff133 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:47:49 2010 +0100 s4:registry - "util" - add also a memory context argument for "reg_key_del_abs" commit 9d8592978e28c492d971a3b5a4c0133febc149ea Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:45:21 2010 +0100 s4:registry - "util" - make "reg_key_add_abs" consistent with "reg_key_del_abs" commit 05d8882a966708f994688fce3b978abb1432bc40 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:44:19 2010 +0100 s4:registry - "util" - fix up memory allocated data commit 96bb09bcf6ed221b1ce11dd4ec91b64d53ff6626 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:26:59 2010 +0100 s4:registry - "dir.c" - fix up dynamic memory allocation operations - Added free operations where needed - Use always the "mem_ctx" for temporary data - Proof with W_ERROR_HAVE_NO_MEMORY if stuff was allocated commit 43170dafbcbe7464bce9b4c6d76532d7d0bf5b9a Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 19:18:56 2010 +0100 s4:registry - adaptions for "add memory contexts for delete value/key functions" commit 64f51380aad484d020093c926512ec79a35bcb93 Author: Matthias Dieter Wallnöfer <mwallnoe...@yahoo.de> Date: Mon Mar 22 18:51:20 2010 +0100 s4:registry - registry.h - add memory contexts for delete value/key functions ----------------------------------------------------------------------- Summary of changes: source4/lib/registry/dir.c | 71 +++++++++++++++++++++++------- source4/lib/registry/hive.c | 10 +++-- source4/lib/registry/interface.c | 10 +++-- source4/lib/registry/ldb.c | 29 ++++--------- source4/lib/registry/local.c | 44 ++++++++++++++----- source4/lib/registry/patchfile.c | 7 ++- source4/lib/registry/patchfile_dotreg.c | 3 + source4/lib/registry/pyregistry.c | 8 ++-- source4/lib/registry/regf.c | 17 +++++-- source4/lib/registry/registry.h | 27 ++++++++---- source4/lib/registry/rpc.c | 9 ++-- source4/lib/registry/samba.c | 3 + source4/lib/registry/tests/hive.c | 14 +++--- source4/lib/registry/tests/registry.c | 6 +- source4/lib/registry/tools/regshell.c | 4 +- source4/lib/registry/util.c | 32 ++++++++------ source4/rpc_server/winreg/rpc_winreg.c | 5 +- 17 files changed, 189 insertions(+), 110 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c index 4380dce..b1f0965 100644 --- a/source4/lib/registry/dir.c +++ b/source4/lib/registry/dir.c @@ -40,9 +40,11 @@ static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, int ret; path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); + W_ERROR_HAVE_NO_MEMORY(path); ret = mkdir(path, 0700); if (ret == 0) { struct dir_key *key = talloc(mem_ctx, struct dir_key); + W_ERROR_HAVE_NO_MEMORY(key); key->key.ops = ®_backend_dir; key->path = talloc_steal(key, path); *result = (struct hive_key *)key; @@ -76,8 +78,7 @@ static WERROR reg_dir_delete_recursive(const char *name) continue; path = talloc_asprintf(name, "%s/%s", name, e->d_name); - if (!path) - return WERR_NOMEM; + W_ERROR_HAVE_NO_MEMORY(path); stat(path, &stbuf); @@ -108,12 +109,16 @@ static WERROR reg_dir_delete_recursive(const char *name) return WERR_GENERAL_FAILURE; } -static WERROR reg_dir_del_key(const struct hive_key *k, const char *name) +static WERROR reg_dir_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *k, + const char *name) { struct dir_key *dk = talloc_get_type(k, struct dir_key); - char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name); + char *child; WERROR ret; + child = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); + W_ERROR_HAVE_NO_MEMORY(child); + ret = reg_dir_delete_recursive(child); talloc_free(child); @@ -136,11 +141,13 @@ static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, } fullpath = talloc_asprintf(mem_ctx, "%s/%s", p->path, name); + W_ERROR_HAVE_NO_MEMORY(fullpath); d = opendir(fullpath); if (d == NULL) { DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno))); + talloc_free(fullpath); return WERR_BADFILE; } closedir(d); @@ -173,27 +180,30 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, char *thispath; /* Check if file is a directory */ - asprintf(&thispath, "%s/%s", dk->path, e->d_name); + thispath = talloc_asprintf(mem_ctx, "%s/%s", dk->path, + e->d_name); + W_ERROR_HAVE_NO_MEMORY(thispath); stat(thispath, &stbuf); if (!S_ISDIR(stbuf.st_mode)) { - SAFE_FREE(thispath); + talloc_free(thispath); continue; } if (i == idx) { struct stat st; *name = talloc_strdup(mem_ctx, e->d_name); + W_ERROR_HAVE_NO_MEMORY(*name); *classname = NULL; stat(thispath, &st); unix_to_nt_time(last_mod_time, st.st_mtime); - SAFE_FREE(thispath); + talloc_free(thispath); closedir(d); return WERR_OK; } i++; - SAFE_FREE(thispath); + talloc_free(thispath); } } @@ -211,6 +221,7 @@ WERROR reg_open_directory(TALLOC_CTX *parent_ctx, return WERR_INVALID_PARAM; dk = talloc(parent_ctx, struct dir_key); + W_ERROR_HAVE_NO_MEMORY(dk); dk->key.ops = ®_backend_dir; dk->path = talloc_strdup(dk, location); *key = (struct hive_key *)dk; @@ -270,10 +281,12 @@ static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key, if(!ISDOT(e->d_name) && !ISDOTDOT(e->d_name)) { char *path = talloc_asprintf(ctx, "%s/%s", dk->path, e->d_name); + W_ERROR_HAVE_NO_MEMORY(path); if (stat(path, &st) < 0) { DEBUG(0, ("Error statting %s: %s\n", path, strerror(errno))); + talloc_free(path); continue; } @@ -308,10 +321,19 @@ static WERROR reg_dir_set_value(struct hive_key *key, const char *name, uint32_t type, const DATA_BLOB data) { const struct dir_key *dk = talloc_get_type(key, struct dir_key); - char *path = talloc_asprintf(dk, "%s/%s", dk->path, name); + char *path; + bool ret; + + path = talloc_asprintf(dk, "%s/%s", dk->path, name); + W_ERROR_HAVE_NO_MEMORY(path); + + ret = file_save(path, data.data, data.length); + + talloc_free(path); - if (!file_save(path, data.data, data.length)) + if (!ret) { return WERR_GENERAL_FAILURE; + } /* FIXME: Type */ @@ -323,12 +345,17 @@ static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx, uint32_t *type, DATA_BLOB *data) { const struct dir_key *dk = talloc_get_type(key, struct dir_key); - char *path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); + char *path; size_t size; char *contents; + path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); + W_ERROR_HAVE_NO_MEMORY(path); + contents = file_load(path, &size, 0, mem_ctx); + talloc_free(path); + if (contents == NULL) return WERR_BADFILE; @@ -364,8 +391,10 @@ static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx, continue; if (i == idx) { - if (name != NULL) + if (name != NULL) { *name = talloc_strdup(mem_ctx, e->d_name); + W_ERROR_HAVE_NO_MEMORY(*name); + } W_ERROR_NOT_OK_RETURN(reg_dir_get_value(mem_ctx, key, *name, type, data)); @@ -380,17 +409,25 @@ static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx, } -static WERROR reg_dir_del_value (struct hive_key *key, const char *name) +static WERROR reg_dir_del_value(TALLOC_CTX *mem_ctx, + struct hive_key *key, const char *name) { const struct dir_key *dk = talloc_get_type(key, struct dir_key); - char *path = talloc_asprintf(key, "%s/%s", dk->path, name); - if (unlink(path) < 0) { - talloc_free(path); + char *path; + int ret; + + path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); + W_ERROR_HAVE_NO_MEMORY(path); + + ret = unlink(path); + + talloc_free(path); + + if (ret < 0) { if (errno == ENOENT) return WERR_BADFILE; return WERR_GENERAL_FAILURE; } - talloc_free(path); return WERR_OK; } diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c index 8bf7c9f..c9cb247 100644 --- a/source4/lib/registry/hive.c +++ b/source4/lib/registry/hive.c @@ -91,9 +91,10 @@ _PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx, desc, key); } -_PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name) +_PUBLIC_ WERROR hive_key_del(TALLOC_CTX *mem_ctx, const struct hive_key *key, + const char *name) { - return key->ops->del_key(key, name); + return key->ops->del_key(mem_ctx, key, name); } _PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx, @@ -163,12 +164,13 @@ WERROR hive_set_sec_desc(struct hive_key *key, return key->ops->set_sec_desc(key, security); } -WERROR hive_key_del_value(struct hive_key *key, const char *name) +WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key, + const char *name) { if (key->ops->delete_value == NULL) return WERR_NOT_SUPPORTED; - return key->ops->delete_value(key, name); + return key->ops->delete_value(mem_ctx, key, name); } WERROR hive_key_flush(struct hive_key *key) diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c index 5d24f6d..c5d5ce8 100644 --- a/source4/lib/registry/interface.c +++ b/source4/lib/registry/interface.c @@ -185,7 +185,8 @@ _PUBLIC_ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx, /** * Delete a key. */ -_PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name) +_PUBLIC_ WERROR reg_key_del(TALLOC_CTX *mem_ctx, struct registry_key *parent, + const char *name) { if (parent == NULL) return WERR_INVALID_PARAM; @@ -193,7 +194,7 @@ _PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name) if (parent->context->ops->delete_key == NULL) return WERR_NOT_SUPPORTED; - return parent->context->ops->delete_key(parent, name); + return parent->context->ops->delete_key(mem_ctx, parent, name); } /** @@ -257,7 +258,8 @@ _PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx, /** * Delete a value. */ -_PUBLIC_ WERROR reg_del_value(struct registry_key *key, const char *valname) +_PUBLIC_ WERROR reg_del_value(TALLOC_CTX *mem_ctx, struct registry_key *key, + const char *valname) { if (key == NULL) return WERR_INVALID_PARAM; @@ -265,7 +267,7 @@ _PUBLIC_ WERROR reg_del_value(struct registry_key *key, const char *valname) if (key->context->ops->delete_value == NULL) return WERR_NOT_SUPPORTED; - return key->context->ops->delete_value(key, valname); + return key->context->ops->delete_value(mem_ctx, key, valname); } /** diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 7ceaa5b..8310b6f 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -712,18 +712,16 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent, return WERR_OK; } -static WERROR ldb_del_value (struct hive_key *key, const char *child) +static WERROR ldb_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key, + const char *child) { int ret; struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data); - TALLOC_CTX *mem_ctx; struct ldb_message *msg; struct ldb_dn *childdn; if ((child == NULL) || (child[0] == '\0')) { /* default value */ - mem_ctx = talloc_init("ldb_del_value"); - msg = talloc_zero(mem_ctx, struct ldb_message); W_ERROR_HAVE_NO_MEMORY(msg); msg->dn = ldb_dn_copy(msg, kd->dn); @@ -734,11 +732,8 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child) ret = ldb_modify(kd->ldb, msg); if (ret != LDB_SUCCESS) { DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb))); - talloc_free(mem_ctx); return WERR_FOOBAR; } - - talloc_free(mem_ctx); } else { /* normal value */ childdn = ldb_dn_copy(kd->ldb, kd->dn); @@ -768,13 +763,13 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child) return WERR_OK; } -static WERROR ldb_del_key(const struct hive_key *key, const char *name) +static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key, + const char *name) { unsigned int i; int ret; struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data); struct ldb_dn *ldap_path; - TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key"); struct ldb_context *c = parentkd->ldb; struct ldb_result *res_keys; struct ldb_result *res_vals; @@ -784,7 +779,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) /* Verify key exists by opening it */ werr = ldb_open_key(mem_ctx, key, name, &hk); if (!W_ERROR_IS_OK(werr)) { - talloc_free(mem_ctx); return werr; } @@ -798,7 +792,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) if (ret != LDB_SUCCESS) { DEBUG(0, ("Error getting subkeys for '%s': %s\n", ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); - talloc_free(mem_ctx); return WERR_FOOBAR; } @@ -809,7 +802,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) if (ret != LDB_SUCCESS) { DEBUG(0, ("Error getting values for '%s': %s\n", ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); - talloc_free(mem_ctx); return WERR_FOOBAR; } @@ -818,7 +810,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) if (ret != LDB_SUCCESS) { DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c))); - talloc_free(mem_ctx); return WERR_FOOBAR; } @@ -827,12 +818,12 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) /* Delete any subkeys */ for (i = 0; i < res_keys->count; i++) { - werr = ldb_del_key(hk, ldb_msg_find_attr_as_string( + werr = ldb_del_key(mem_ctx, hk, + ldb_msg_find_attr_as_string( res_keys->msgs[i], "key", NULL)); if (!W_ERROR_IS_OK(werr)) { ret = ldb_transaction_cancel(c); - talloc_free(mem_ctx); return werr; } } @@ -840,12 +831,12 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) /* Delete any values */ for (i = 0; i < res_vals->count; i++) { - werr = ldb_del_value(hk, ldb_msg_find_attr_as_string( + werr = ldb_del_value(mem_ctx, hk, + ldb_msg_find_attr_as_string( res_vals->msgs[i], "value", NULL)); if (!W_ERROR_IS_OK(werr)) { ret = ldb_transaction_cancel(c); - talloc_free(mem_ctx); return werr; } } @@ -858,7 +849,6 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) { DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c))); ret = ldb_transaction_cancel(c); - talloc_free(mem_ctx); return WERR_FOOBAR; } @@ -869,12 +859,9 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) { DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c))); ret = ldb_transaction_cancel(c); - talloc_free(mem_ctx); return WERR_FOOBAR; } - talloc_free(mem_ctx); - /* reset cache */ talloc_free(parentkd->subkeys); parentkd->subkeys = NULL; diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c index 458239b..be48729 100644 --- a/source4/lib/registry/local.c +++ b/source4/lib/registry/local.c @@ -57,9 +57,11 @@ struct registry_key *reg_import_hive_key(struct registry_context *ctx, parent_path.elements = elements; local_key = talloc(ctx, struct local_key); - local_key->hive_key = talloc_steal(local_key, hive); - local_key->global.context = talloc_reference(local_key, ctx); - local_key->path = parent_path; + if (local_key != NULL) { + local_key->hive_key = talloc_reference(local_key, hive); + local_key->global.context = talloc_reference(local_key, ctx); + local_key->path = parent_path; + } return (struct registry_key *)local_key; } @@ -70,9 +72,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx, const char *path, struct registry_key **result) { - char *orig = talloc_strdup(mem_ctx, path), - *curbegin = orig, - *curend = strchr(orig, '\\'); + char *orig, *curbegin, *curend; struct local_key *local_parent = talloc_get_type(parent, struct local_key); struct hive_key *curkey = local_parent->hive_key; @@ -80,9 +80,15 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx, const char **elements = NULL; int el; + orig = talloc_strdup(mem_ctx, path); + W_ERROR_HAVE_NO_MEMORY(orig); + curbegin = orig; + curend = strchr(orig, '\\'); + if (local_parent->path.elements != NULL) { elements = talloc_array(mem_ctx, const char *, str_list_length(local_parent->path.elements) + 1); + W_ERROR_HAVE_NO_MEMORY(elements); for (el = 0; local_parent->path.elements[el] != NULL; el++) { elements[el] = talloc_reference(elements, local_parent->path.elements[el]); @@ -97,7 +103,9 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx, if (curend != NULL) *curend = '\0'; elements = talloc_realloc(mem_ctx, elements, const char *, el+2); + W_ERROR_HAVE_NO_MEMORY(elements); elements[el] = talloc_strdup(elements, curbegin); + W_ERROR_HAVE_NO_MEMORY(elements[el]); el++; elements[el] = NULL; error = hive_get_key_by_name(mem_ctx, curkey, @@ -169,15 +177,19 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx, const char **elements; unsigned int i; const char *last_part; + char *trunc_name; last_part = strrchr(name, '\\'); if (last_part == NULL) { last_part = name; local_parent = (struct local_key *)parent_key; } else { + trunc_name = talloc_strndup(mem_ctx, name, last_part - name); + W_ERROR_HAVE_NO_MEMORY(trunc_name); W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key, - talloc_strndup(mem_ctx, name, last_part-name), + trunc_name, (struct registry_key **)&local_parent)); + talloc_free(trunc_name); last_part++; } @@ -188,16 +200,19 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx, if (local_parent->path.elements != NULL) { elements = talloc_array(hivekey, const char *, str_list_length(local_parent->path.elements)+2); + W_ERROR_HAVE_NO_MEMORY(elements); for (i = 0; local_parent->path.elements[i] != NULL; i++) { elements[i] = talloc_reference(elements, local_parent->path.elements[i]); } } else { elements = talloc_array(hivekey, const char *, 2); + W_ERROR_HAVE_NO_MEMORY(elements); i = 0; -- Samba Shared Repository