From: Emil Velikov Date: Sun, 2 Aug 2026 12:26:13 +0000 (+0100) Subject: modinfo: rework parm string length validation X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b2bed9822dbc93f2365fc26363f017f08e60a42;p=thirdparty%2Fkmod.git modinfo: rework parm string length validation Currently, we if we fail to find a name, description or type in the value token we emit an error and continue. At the same time, if the name is longer than INT_MAX we error out. Move the validation (overall strlen(value), which includes namelen) further up the call stack and make it a non-fatal. This allows us to garbage collect the no longer reachable error paths around {add,process}_param(). Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/451 Signed-off-by: Lucas De Marchi --- diff --git a/tools/modinfo.c b/tools/modinfo.c index bae282f..02d8121 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -39,18 +39,15 @@ enum parm_info { parm_type, }; -static int add_param(const char *name, size_t namelen, enum parm_info parm_info, - const char *value, struct param *params, unsigned int params_count) +static void add_param(const char *name, int namelen, enum parm_info parm_info, + const char *value, struct param *params, unsigned int params_count) { - if (namelen > INT_MAX) - return -EINVAL; - /* We are guaranteed to have a match, or at least one empty entry */ for (unsigned int i = 0; i < params_count; i++) { struct param *it = ¶ms[i]; - if (it->name != NULL && (it->namelen != (int)namelen || - memcmp(it->name, name, namelen) != 0)) { + if (it->name != NULL && + (it->namelen != namelen || memcmp(it->name, name, namelen) != 0)) { continue; } @@ -67,37 +64,28 @@ static int add_param(const char *name, size_t namelen, enum parm_info parm_info, } break; } - - return 0; } -static int process_parm(enum parm_info parm_info, const char *value, struct param *params, - unsigned int params_count) +static void process_parm(enum parm_info parm_info, const char *value, + struct param *params, unsigned int params_count) { const char *name; - size_t namelen; + int namelen; const char *colon = strchr(value, ':'); - int ret; if (colon == NULL) { ERR("Missing ':' in value \"%s\"\n", value); - return 0; + return; } if (colon == value) { ERR("Missing param name in value \"%s\"\n", value); - return 0; + return; } name = value; - namelen = colon - value; - ret = add_param(name, namelen, parm_info, colon + 1, params, params_count); - if (ret < 0) { - ERR("Unable to add parameter: %s\n", strerror(-ret)); - return -ENOMEM; - } - - return 0; + namelen = (int)(colon - value); + add_param(name, namelen, parm_info, colon + 1, params, params_count); } static void print_line(const char *key, const char *value) @@ -234,9 +222,12 @@ static int modinfo_do(struct kmod_module *mod) continue; } - err = process_parm(parm_info, value, params, params_count); - if (err < 0) - goto end; + if (strlen(value) > INT_MAX) { + ERR("%s's value is longer than INT_MAX\n", + parm_info == parm_desc ? "parm" : "parmtype"); + continue; + } + process_parm(parm_info, value, params, params_count); } for (unsigned int i = 0; i < params_count; i++) {