From f806a238f7dea936cbc15ad91590c40ac27c2e8d Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 4 Jul 2017 21:43:56 +0100 Subject: 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 --- sys-utils/rfkill.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sys-utils/rfkill.c') diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index 2f744ecf6..08002b44f 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; } -- cgit v1.2.3-55-g7522