]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rfkill: check id number refers to a device that exists
authorSami Kerola <kerolasa@iki.fi>
Tue, 4 Jul 2017 20:43:56 +0000 (21:43 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 30 Aug 2017 19:32:49 +0000 (20:32 +0100)
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>
sys-utils/rfkill.c

index 2f744ecf62f37fc57c4bd8cc80455790dec580fc..08002b44f0eea7a4db828eef27a410369a8a5b23 100644 (file)
@@ -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;
        }