Fix segfault in json plugin

This commit is contained in:
vdutta 2021-12-06 11:06:52 +05:30
parent c9789e90d6
commit 0ef1ad0dd7
5 changed files with 33 additions and 3 deletions

1
.gitignore vendored
View file

@ -40,3 +40,4 @@ tools/__pycache__
*.gcno *.gcno
*\.log *\.log
.libs .libs
m4/

View file

@ -702,7 +702,11 @@ static char *ubus_get_value(json_object *mapping_obj, int json_version, char *re
} }
json_object_object_get_ex(res, buf, &arr_obj); json_object_object_get_ex(res, buf, &arr_obj);
nbre_entries = (arr_obj) ? json_object_array_length(arr_obj) : 0;
if (arr_obj != NULL && json_object_is_type(arr_obj, json_type_array) == 1) {
nbre_entries = json_object_array_length(arr_obj);
}
dmasprintf(&value, "%d", nbre_entries); dmasprintf(&value, "%d", nbre_entries);
goto end; goto end;
} }

View file

@ -99,8 +99,10 @@ int main(int argc, char *argv[])
} }
ubus_ctx = ubus_connect(NULL); ubus_ctx = ubus_connect(NULL);
if (ubus_ctx == NULL) if (ubus_ctx == NULL) {
fprintf(stderr, "Failed to connect with ubus\n");
return -1; return -1;
}
dm_config_ubus(ubus_ctx); dm_config_ubus(ubus_ctx);

View file

@ -39,6 +39,28 @@
} }
] ]
}, },
"MHubNumberOfEntries": {
"type": "int",
"version": "2.14",
"protocols": [
"cwmp",
"usp"
],
"read": true,
"write": false,
"datatype": "int",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "proxd",
"method": "list",
"args": {},
"key": "numofdevices"
}
}
]
},
"Device.PD2.{i}.MiniHub.{i}.": { "Device.PD2.{i}.MiniHub.{i}.": {
"type": "object", "type": "object",
"version": "2.14", "version": "2.14",

View file

@ -2,5 +2,6 @@
"devices": [ "devices": [
{ "name": "one"}, { "name": "one"},
{"name": "two"} {"name": "two"}
] ],
"numofdevices": "1"
} }