]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: add assert to make coverity happy
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Feb 2021 08:17:46 +0000 (09:17 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Feb 2021 08:17:46 +0000 (09:17 +0100)
Coverity says:
CID 1446387 (#1 of 1): Bad bit shift operation (BAD_SHIFT)
8. negative_shift: In expression 1U << (int)cmd, shifting by a negative amount
has undefined behavior. The shift amount, cmd, is -22.

I don't think there's any issue, unless we forget to set token->data
appropriately. Let's add an assert.

src/udev/udev-rules.c

index e12225ca39c258b223c53df028799f06acac2917..96a391c07c8dbd0192bf5ca342954796587a107b 100644 (file)
@@ -1773,6 +1773,7 @@ static int udev_rule_apply_token_to_event(
         }
         case TK_M_IMPORT_BUILTIN: {
                 UdevBuiltinCommand cmd = PTR_TO_UDEV_BUILTIN_CMD(token->data);
+                assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
                 unsigned mask = 1U << (int) cmd;
 
                 if (udev_builtin_run_once(cmd)) {