From: Sami Kerola Date: Tue, 4 Jul 2017 20:43:56 +0000 (+0100) Subject: rfkill: check id number refers to a device that exists X-Git-Tag: v2.31-rc1~98^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f806a238f7dea936cbc15ad91590c40ac27c2e8d;p=thirdparty%2Futil-linux.git rfkill: check id number refers to a device that exists Earlier all commands happily accepted without detecting failure when none-existing id number was used. For example: $ rfkill block 2017; echo $? 0 The same input after this change looks following. $ rfkill block 2017; echo $? rfkill: invalid identifier: 2017 1 Signed-off-by: Sami Kerola --- diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index 2f744ecf62..08002b44f0 100644 --- a/sys-utils/rfkill.c +++ b/sys-utils/rfkill.c @@ -244,8 +244,15 @@ static struct rfkill_id rfkill_id_to_type(const char *s) } } else if (isdigit(*s)) { /* assume a numeric character implies an index. */ + char filename[64]; + ret.index = strtou32_or_err(s, _("invalid identifier")); - ret.result = RFKILL_IS_INDEX; + snprintf(filename, sizeof(filename) - 1, + _PATH_SYS_RFKILL "/rfkill%" PRIu32 "/name", ret.index); + if (access(filename, F_OK) == 0) + ret.result = RFKILL_IS_INDEX; + else + ret.result = RFKILL_IS_INVALID; return ret; }