summaryrefslogtreecommitdiff
path: root/source4/lib/registry
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-13 19:29:03 +0100
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-14 18:46:20 +0100
commitcd3c870333d49460c9598a9928622454cd2cefc5 (patch)
tree87f169acceb8415f14ed3f599082a430afca74cc /source4/lib/registry
parent3c6792bc76323f821bc9e44ea3d724ce39e9081f (diff)
downloadsamba-cd3c870333d49460c9598a9928622454cd2cefc5.tar.gz
samba-cd3c870333d49460c9598a9928622454cd2cefc5.tar.bz2
samba-cd3c870333d49460c9598a9928622454cd2cefc5.zip
s4:registry - ldb.c - Consider result values in "reg_ldb_pack_value"
Break on errors and return NULL and otherwise the message pointer.
Diffstat (limited to 'source4/lib/registry')
-rw-r--r--source4/lib/registry/ldb.c76
1 files changed, 59 insertions, 17 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index f226cbf450..0fab8472a9 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -98,10 +98,26 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
const char *name,
uint32_t type, DATA_BLOB data)
{
- struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message);
- char *type_s;
+ struct ldb_message *msg;
+ char *name_dup, *type_str;
+ int ret;
+
+ msg = talloc_zero(mem_ctx, struct ldb_message);
+ if (msg == NULL) {
+ return NULL;
+ }
+
+ name_dup = talloc_strdup(msg, name);
+ if (name_dup == NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
- ldb_msg_add_string(msg, "value", talloc_strdup(mem_ctx, name));
+ ret = ldb_msg_add_string(msg, "value", name_dup);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return NULL;
+ }
switch (type) {
case REG_SZ:
@@ -109,25 +125,37 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
if ((data.length > 0) && (data.data != NULL)
&& (data.data[0] != '\0')) {
struct ldb_val *val;
+ bool ret2;
val = talloc_zero(msg, struct ldb_val);
- convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
- (void *)data.data,
- data.length,
- (void **)&val->data, &val->length, false);
- ldb_msg_add_value(msg, "data", val, NULL);
+ if (val == NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
+
+ ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
+ (void *)data.data, data.length,
+ (void **)&val->data, &val->length,
+ false);
+ ret = ldb_msg_add_value(msg, "data", val, NULL);
} else {
- ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
+ ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
}
break;
case REG_DWORD:
if ((data.length > 0) && (data.data != NULL)) {
- ldb_msg_add_string(msg, "data",
- talloc_asprintf(mem_ctx, "0x%x",
- IVAL(data.data, 0)));
+ char *conv_str;
+
+ conv_str = talloc_asprintf(msg, "0x%x", IVAL(data.data, 0));
+ if (conv_str == NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
+
+ ret = ldb_msg_add_string(msg, "data", conv_str);
} else {
- ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
+ ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
}
break;
@@ -135,15 +163,29 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
default:
if ((data.length > 0) && (data.data != NULL)
&& (data.data[0] != '\0')) {
- ldb_msg_add_value(msg, "data", &data, NULL);
+ ret = ldb_msg_add_value(msg, "data", &data, NULL);
} else {
- ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
+ ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
}
break;
}
- type_s = talloc_asprintf(mem_ctx, "%u", type);
- ldb_msg_add_string(msg, "type", type_s);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return NULL;
+ }
+
+ type_str = talloc_asprintf(mem_ctx, "%u", type);
+ if (type_str == NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
+
+ ret = ldb_msg_add_string(msg, "type", type_str);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return NULL;
+ }
return msg;
}