From 3a40e32da9b3514da6a3dca1dedc390e606ddb54 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Tue, 30 Jul 2024 15:18:13 +0200 Subject: [PATCH] res: ucmd-module: return count=0 when sid_ucmd_dev_alias_get_* param check fails --- src/resource/ubridge.c | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/resource/ubridge.c b/src/resource/ubridge.c index 63b5e3f9..38a78bac 100644 --- a/src/resource/ubridge.c +++ b/src/resource/ubridge.c @@ -3619,12 +3619,13 @@ const char **_do_sid_ucmd_dev_alias_get(sid_res_t *mod_res, const char **sid_ucmd_dev_alias_get(sid_res_t *mod_res, struct sid_ucmd_ctx *ucmd_ctx, const char *alias_key, size_t *count) { - if (!mod_res || !ucmd_ctx) - return NULL; - - if (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && - !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res)) + if (!mod_res || !ucmd_ctx || + (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && + !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res))) { + if (count) + *count = 0; return NULL; + } return _do_sid_ucmd_dev_alias_get(mod_res, ucmd_ctx, NULL, _owner_name(mod_res), alias_key, count); } @@ -3635,12 +3636,13 @@ const char **sid_ucmd_dev_alias_get_foreign_dev(sid_res_t *mod_res, const char *alias_key, size_t *count) { - if (!mod_res || !ucmd_ctx || UTIL_STR_EMPTY(foreign_dev_id)) - return NULL; - - if (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && - !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res)) + if (!mod_res || !ucmd_ctx || UTIL_STR_EMPTY(foreign_dev_id) || + (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && + !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res))) { + if (count) + *count = 0; return NULL; + } return _do_sid_ucmd_dev_alias_get(mod_res, ucmd_ctx, foreign_dev_id, _owner_name(mod_res), alias_key, count); } @@ -3651,12 +3653,13 @@ const char **sid_ucmd_dev_alias_get_foreign_mod(sid_res_t *mod_res, const char *alias_key, size_t *count) { - if (!mod_res || !ucmd_ctx) - return NULL; - - if (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && - !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res)) + if (!mod_res || !ucmd_ctx || + (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && + !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res))) { + if (count) + *count = 0; return NULL; + } return _do_sid_ucmd_dev_alias_get(mod_res, ucmd_ctx, NULL, foreign_mod_name, alias_key, count); } @@ -3668,12 +3671,13 @@ const char **sid_ucmd_dev_alias_get_foreign_dev_mod(sid_res_t *mod_res const char *alias_key, size_t *count) { - if (!mod_res || !ucmd_ctx || UTIL_STR_EMPTY(foreign_dev_id)) - return NULL; - - if (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && - !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res)) + if (!mod_res || !ucmd_ctx || UTIL_STR_EMPTY(foreign_dev_id) || + (!sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->block_mod_reg_res) && + !sid_mod_reg_match_dep(mod_res, ucmd_ctx->common->type_mod_reg_res))) { + if (count) + *count = 0; return NULL; + } return _do_sid_ucmd_dev_alias_get(mod_res, ucmd_ctx, foreign_dev_id, foreign_mod_name, alias_key, count); }