[Openais] [corosync trunk PATCH] make sure key_names past from confdb are null terminated.
angus salkeld
angus.salkeld at alliedtelesis.co.nz
Mon Nov 30 15:57:36 PST 2009
Hi
This makes sure that calls to object_XYZ_typed() have null terminated key names.
Fabio: can you test this please?
This fixes the errors I was getting from testconfdb.
inline & attached.
Note: there is a testconfdb change I'll rip out (for readability).
-Angus
diff --git a/exec/objdb.c b/exec/objdb.c
index 3334460..d57c009 100644
--- a/exec/objdb.c
+++ b/exec/objdb.c
@@ -659,7 +659,14 @@ static int object_key_create (
const void *value,
size_t value_len)
{
- return object_key_create_typed (object_handle, key_name,
+ char *key_name_terminated = (char*)key_name;
+ if (key_name_terminated[key_len-1] != '\0') {
+ key_name_terminated = malloc (key_len + 1);
+ memcpy (key_name_terminated, key_name, key_len);
+ key_name_terminated[key_len] = '\0';
+ }
+
+ return object_key_create_typed (object_handle, key_name_terminated,
value, value_len, OBJDB_VALUETYPE_ANY);
}
@@ -973,9 +980,17 @@ static int object_key_get (
size_t *value_len)
{
objdb_value_types_t t;
+ char *key_name_terminated = (char*)key_name;
+
+ if (key_name_terminated[key_len-1] != '\0') {
+ key_name_terminated = malloc (key_len + 1);
+ memcpy (key_name_terminated, key_name, key_len);
+ key_name_terminated[key_len] = '\0';
+ }
+
return object_key_get_typed(object_handle,
- key_name,
- value, value_len, &t);
+ key_name_terminated,
+ value, value_len, &t);
}
static int object_key_increment (
@@ -1484,9 +1499,10 @@ static int object_key_iter(hdb_handle_t parent_object_handle,
objdb_value_types_t t;
int ret;
char *str;
+
ret = object_key_iter_typed (parent_object_handle, (char**)key_name, value, value_len, &t);
str = *key_name;
- *key_len = strlen(str);
+ *key_len = strlen(str) + 1;
return ret;
}
diff --git a/test/testconfdb.c b/test/testconfdb.c
index 3017a69..52888b0 100644
--- a/test/testconfdb.c
+++ b/test/testconfdb.c
@@ -67,6 +67,9 @@ static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object
int res;
int i;
+
+ system("corosync-objctl");
+ return;
/* Show the keys */
res = confdb_key_iter_start(handle, parent_object_handle);
if (res != CS_OK) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.p
Type: application/octet-stream
Size: 1873 bytes
Desc: not available
Url : http://lists.linux-foundation.org/pipermail/openais/attachments/20091201/aa0d21f8/attachment.obj
More information about the Openais
mailing list