summaryrefslogtreecommitdiffstats
path: root/sys-utils/rfkill.c
diff options
context:
space:
mode:
authorSami Kerola2017-07-04 22:43:56 +0200
committerSami Kerola2017-08-30 21:32:49 +0200
commitf806a238f7dea936cbc15ad91590c40ac27c2e8d (patch)
tree2089efa99a863a0398e5baa3813894b6e4ed4b17 /sys-utils/rfkill.c
parentrfkill: use back and forward compatible test (diff)
downloadkernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.tar.gz
kernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.tar.xz
kernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.zip
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 <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/rfkill.c')
-rw-r--r--sys-utils/rfkill.c9
1 files changed, 8 insertions, 1 deletions
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;
}