diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f382213b..ebd8f9c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ variables: DEBUG: 'TRUE' SOURCE_FOLDER: "." FLAWFINDER_OPTIONS: "-m 4 --error-level=5" - CPPCHECK_OPTIONS: " --enable=information -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBF_TR181 -DBBF_VENDOR_IOPSYS --inline-suppr -i test/" + CPPCHECK_OPTIONS: " --enable=warning --enable=performance --enable=portability --enable=information -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBF_TR181 -DBBF_VENDOR_IOPSYS --inline-suppr -i test/" include: - project: 'iopsys/gitlab-ci-pipeline' diff --git a/bbfdmd/ubus/bbfdmd.c b/bbfdmd/ubus/bbfdmd.c index de75fc99..0a953ba9 100644 --- a/bbfdmd/ubus/bbfdmd.c +++ b/bbfdmd/ubus/bbfdmd.c @@ -106,6 +106,7 @@ static void bbfdm_cleanup(struct bbfdm_context *u) blob_buf_free(&u->dm_schema); /* DotSo Plugin */ free_dotso_plugin(deamon_lib_handle); + deamon_lib_handle = NULL; /* JSON Plugin */ free_json_plugin(); diff --git a/bbfdmd/ubus/cli.c b/bbfdmd/ubus/cli.c index 9c5e8278..881ce9b3 100644 --- a/bbfdmd/ubus/cli.c +++ b/bbfdmd/ubus/cli.c @@ -577,6 +577,7 @@ end: bbf_global_clean(CLI_DM_ROOT_OBJ); } free_dotso_plugin(cli_lib_handle); + cli_lib_handle = NULL; } else if (strcasecmp(cli_data->in_type, "JSON") == 0) { if (CLI_DM_ROOT_OBJ) { bbf_ctx_clean(&cli_data->bbf_ctx); diff --git a/bbfdmd/ubus/plugin.c b/bbfdmd/ubus/plugin.c index 767efbcc..d765f833 100644 --- a/bbfdmd/ubus/plugin.c +++ b/bbfdmd/ubus/plugin.c @@ -86,10 +86,8 @@ int load_dotso_plugin(void **lib_handle, const char *file_path, int free_dotso_plugin(void *lib_handle) { - if (lib_handle) { + if (lib_handle) dlclose(lib_handle); - lib_handle = NULL; - } return 0; } diff --git a/libbbfdm-api/dmbbf.c b/libbbfdm-api/dmbbf.c index 78425d4e..0f619685 100644 --- a/libbbfdm-api/dmbbf.c +++ b/libbbfdm-api/dmbbf.c @@ -859,7 +859,7 @@ static char *get_value_by_reference(struct dmctx *ctx, char *value) char buf_val[MAX_DM_PATH * 4] = {0}; bool path_resolved = false; - if (DM_STRLEN(value) == 0 || !DM_STRSTR(value, "==")) + if (DM_STRLEN(value) == 0 || !DM_LSTRSTR(value, "==")) return value; DM_STRNCPY(buf, value, sizeof(buf)); @@ -884,7 +884,7 @@ static char *get_value_by_reference(struct dmctx *ctx, char *value) if (DM_STRLEN(match_str) == 0) goto end; - int n = sscanf(match_str, "%[^=]==\"%[^\"]\"", key_name, key_value); + int n = sscanf(match_str, "%255[^=]==\"%255[^\"]\"", key_name, key_value); if (n != 2) goto end; @@ -1089,12 +1089,12 @@ static int get_ubus_value(struct dmctx *dmctx, struct dmnode *node) const char *flag = json_object_get_string(flag_obj); - if (DM_STRCMP(flag, "Reference") == 0) { + if (DM_LSTRCMP(flag, "Reference") == 0) { data = get_value_by_reference(dmctx, data); *dm_flags |= DM_FLAG_REFERENCE; - } else if (DM_STRCMP(flag, "Unique") == 0) { + } else if (DM_LSTRCMP(flag, "Unique") == 0) { *dm_flags |= DM_FLAG_UNIQUE; - } else if (DM_STRCMP(flag, "Linker") == 0) { + } else if (DM_LSTRCMP(flag, "Linker") == 0) { *dm_flags |= DM_FLAG_LINKER; } } @@ -1149,7 +1149,7 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) char *data = dmjson_get_value(res_obj, 1, "data"); char *type = dmjson_get_value(res_obj, 1, "type"); - if (DM_STRCMP(type, "xsd:object") == 0) { //Object + if (DM_LSTRCMP(type, "xsd:object") == 0) { //Object const char **unique_keys = NULL; json_object *input_array = dmjson_get_obj(res_obj, 1, "input"); @@ -1169,7 +1169,7 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) } add_list_parameter(dmctx, dmstrdup(path), dmstrdup(data), "xsd:object", (char *)unique_keys); - } else if (DM_STRCMP(type, "xsd:command") == 0) { //Command Leaf + } else if (DM_LSTRCMP(type, "xsd:command") == 0) { //Command Leaf operation_args *op = NULL; op = dmcalloc(1, sizeof(operation_args)); @@ -1205,7 +1205,7 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) } add_list_parameter(dmctx, dmstrdup(path), (char *)op, "xsd:command", dmstrdup(data)); - } else if (DM_STRCMP(type, "xsd:event") == 0) { //Event Leaf + } else if (DM_LSTRCMP(type, "xsd:event") == 0) { //Event Leaf event_args *ev = NULL; json_object *input_array = dmjson_get_obj(res_obj, 1, "input"); @@ -1400,7 +1400,7 @@ static bool is_reference_parameter(char *ubus_name, char *param_name, json_objec char *flags_list = dmjson_get_value_array_all(res_obj, ",", 1, "flags"); - return DM_STRSTR(flags_list, "Reference") ? true : false; + return DM_LSTRSTR(flags_list, "Reference") ? true : false; } static int set_ubus_value(struct dmctx *dmctx, struct dmnode *node) @@ -1628,7 +1628,7 @@ static int get_ubus_reference_value(struct dmctx *dmctx, struct dmnode *node) const char *flag = json_object_get_string(flag_obj); - if (DM_STRCMP(flag, "Linker") == 0) { + if (DM_LSTRCMP(flag, "Linker") == 0) { char *data = dmjson_get_value(res_obj, 1, "data"); dmctx->linker = data ? dmstrdup(data) : ""; dmctx->stop = true; @@ -2287,7 +2287,7 @@ static int mparam_set_value(DMPARAM_ARGS) } } - if ((leaf->dm_falgs & DM_FLAG_REFERENCE) && !DM_STRSTR(dmctx->in_value, "=>")) { + if ((leaf->dm_falgs & DM_FLAG_REFERENCE) && !DM_LSTRSTR(dmctx->in_value, "=>")) { get_reference_paramater_value(dmctx, dmctx->in_value, param_value, sizeof(param_value)); } else { snprintf(param_value, sizeof(param_value), "%s", dmctx->in_value); diff --git a/libbbfdm-api/dmcommon.c b/libbbfdm-api/dmcommon.c index d9946e73..ae0c7c58 100644 --- a/libbbfdm-api/dmcommon.c +++ b/libbbfdm-api/dmcommon.c @@ -957,7 +957,7 @@ char *remove_str_from_str_list(char *str_list, const char *delimitor, const char for (pch = strtok_r(list, delimitor, &spch); pch != NULL; pch = strtok_r(NULL, delimitor, &spch)) { - if (DM_STRCMP(pch, str) == 0) + if (DM_LSTRCMP(str, pch) == 0) continue; pos += snprintf(&res[pos], len + 1 - pos, "%s%s", pch, delimitor); diff --git a/libbbfdm-api/dmplugin.c b/libbbfdm-api/dmplugin.c index 5ac00bfb..4c9aa195 100644 --- a/libbbfdm-api/dmplugin.c +++ b/libbbfdm-api/dmplugin.c @@ -330,7 +330,7 @@ static void dm_check_dynamic_obj(DMNODE *parent_node, DMOBJ *entryobj, char *ful DMOBJ *find_entry_obj(DMOBJ *entryobj, char *obj_path) { if (!entryobj || !obj_path) - return false; + return NULL; DMNODE node = {.current_object = ""}; DMOBJ *obj = NULL; @@ -441,9 +441,9 @@ int load_plugins(DMOBJ *dm_entryobj, DM_MAP_VENDOR *dm_VendorExtension[], DM_MAP snprintf(buf, sizeof(buf), "%s/%s", plugin_path, files[i]); - if (DM_STRSTR(files[i], ".json")) { + if (DM_LSTRSTR(files[i], ".json")) { load_json_plugins(dm_entryobj, buf); - } else if (DM_STRSTR(files[i], ".so")) { + } else if (DM_LSTRSTR(files[i], ".so")) { load_dotso_plugins(dm_entryobj, buf); } diff --git a/libbbfdm-api/plugin/json_plugin.c b/libbbfdm-api/plugin/json_plugin.c index 1d53c99c..7809e7b4 100644 --- a/libbbfdm-api/plugin/json_plugin.c +++ b/libbbfdm-api/plugin/json_plugin.c @@ -1581,6 +1581,7 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl struct json_object *type = NULL, *protocols = NULL, *write = NULL, *async = NULL, *flags = NULL; char full_param[512] = {0}; size_t n_proto, n_flags; + // cppcheck-suppress nullPointerRedundantCheck char **in_p = NULL, **out_p = NULL, **ev_arg = NULL, **tmp = NULL; if (!jobj || !pleaf)