udev: avoid reading before empty capability masks

When input_id prints a decoded capability bitmap, an all-zero
bitmap can decrement the index to zero.

Check the index before reading bitmask[val - 1].

Reproducer:
  udevadm test-builtin input_id with an all-zero capability mask

Follow-up:
  912541b024
This commit is contained in:
dongshengyuan
2026-07-13 10:30:25 +08:00
parent 9a09141cae
commit 9725124635

View File

@@ -118,7 +118,7 @@ static void get_cap_mask(
val = bitmask_size / sizeof (unsigned long);
/* skip trailing zeros */
while (bitmask[val-1] == 0 && val > 0)
while (val > 0 && bitmask[val-1] == 0)
--val;
/* IN_SET() cannot be used in assert_cc(). */