From 8d2581bacb58fc24f3007cf4b8a987c4712d4c03 Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Thu, 25 Nov 2021 17:34:07 +0100 Subject: [PATCH] bbf: fix a crash when the 'access' option is not defined in the JSON file --- dmdynamicjson.c | 3 +++ libbbf_api/dmbbf.c | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dmdynamicjson.c b/dmdynamicjson.c index f062dac6..32e19585 100644 --- a/dmdynamicjson.c +++ b/dmdynamicjson.c @@ -1532,6 +1532,9 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, i pobj[index].leaf = NULL; } + //permission: Define object as readable by default + pobj[index].permission = &DMREAD; + json_object_object_foreach(jobj, key, json_obj) { //bbfdm_type if (strcmp(key, "protocols") == 0) { diff --git a/libbbf_api/dmbbf.c b/libbbf_api/dmbbf.c index 0be184ae..fe6e13da 100644 --- a/libbbf_api/dmbbf.c +++ b/libbbf_api/dmbbf.c @@ -1398,8 +1398,7 @@ static int mparam_get_schema_name(DMPARAM_ARGS) * ***********************/ static int mobj_get_supported_dm(DMOBJECT_ARGS) { - - char *perm = permission->val; + char *perm = permission ? permission->val : "0"; char *refparam = node->current_object; const char **unique_keys = NULL; @@ -1420,22 +1419,21 @@ static int mparam_get_supported_dm(DMPARAM_ARGS) dmastrcat(&refparam, node->current_object, lastname); - if(node->matched) { - if(type == DMT_EVENT) { - if(dmctx->isevent) { + if (node->matched) { + if (type == DMT_EVENT) { + if (dmctx->isevent) { if (get_cmd) (get_cmd)(refparam, dmctx, data, instance, &value); add_list_parameter(dmctx, refparam, value, DMT_TYPE[type], NULL); } - } else if(type == DMT_COMMAND) { + } else if (type == DMT_COMMAND) { if(dmctx->iscommand) { if (get_cmd) (get_cmd)(refparam, dmctx, data, instance, &value); - //add_list_parameter(dmctx, refparam, value, permission->val, NULL); add_list_parameter(dmctx, refparam, value, DMT_TYPE[type], permission->val); } }