projects
/
project
/
procd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
initialize dest in cmd_add_string() to not segfault on empty strings
[project/procd.git]
/
hotplug-rule.c
diff --git
a/hotplug-rule.c
b/hotplug-rule.c
index
7508b1d
..
1f3189d
100644
(file)
--- a/
hotplug-rule.c
+++ b/
hotplug-rule.c
@@
-306,7
+306,8
@@
static int rule_process_expr(struct blob_attr *cur, struct blob_attr *msg)
bool found;
int ret;
bool found;
int ret;
- if (blobmsg_type(cur) != BLOBMSG_TYPE_ARRAY) {
+ if (blobmsg_type(cur) != BLOBMSG_TYPE_ARRAY ||
+ blobmsg_type(blobmsg_data(cur)) != BLOBMSG_TYPE_STRING) {
rule_error(cur, "Unexpected element type");
return -1;
}
rule_error(cur, "Unexpected element type");
return -1;
}
@@
-324,7
+325,7
@@
static void cmd_add_string(const char *pattern, struct blob_attr *msg)
int len = 0;
bool var = false;
int len = 0;
bool var = false;
- blobmsg_alloc_string_buffer(&b, NULL, 1);
+
dest =
blobmsg_alloc_string_buffer(&b, NULL, 1);
str = alloca(strlen(pattern) + 1);
strcpy(str, pattern);
next = str;
str = alloca(strlen(pattern) + 1);
strcpy(str, pattern);
next = str;
@@
-353,7
+354,7
@@
static void cmd_add_string(const char *pattern, struct blob_attr *msg)
}
if (cur_len) {
}
if (cur_len) {
- dest = blobmsg_realloc_string_buffer(&b, cur_len);
+ dest = blobmsg_realloc_string_buffer(&b, cur_len
+ 1
);
memcpy(dest + len, cur, cur_len);
len += cur_len;
}
memcpy(dest + len, cur, cur_len);
len += cur_len;
}
@@
-398,6
+399,12
@@
static int __rule_process_cmd(struct blob_attr *cur, struct blob_attr *msg)
bool found;
int ret;
bool found;
int ret;
+ if (blobmsg_type(cur) != BLOBMSG_TYPE_ARRAY ||
+ blobmsg_type(blobmsg_data(cur)) != BLOBMSG_TYPE_STRING) {
+ rule_error(cur, "Unexpected element type");
+ return -1;
+ }
+
ret = __rule_process_type(cur, msg, cmd, ARRAY_SIZE(cmd), &found);
if (found)
return ret;
ret = __rule_process_type(cur, msg, cmd, ARRAY_SIZE(cmd), &found);
if (found)
return ret;
@@
-460,7
+467,7
@@
rule_file_load(const char *filename)
return NULL;
obj = json_object_from_file((char *) filename);
return NULL;
obj = json_object_from_file((char *) filename);
- if (
!obj
)
+ if (
is_error(obj)
)
return NULL;
if (!json_object_is_type(obj, json_type_array)) {
return NULL;
if (!json_object_is_type(obj, json_type_array)) {