Skip to content

Commit

Permalink
udev_device.c: fix integer overflow
Browse files Browse the repository at this point in the history
Bitwise AND operation can produce value that may be larger than
test_bit() return value. Convert result to bool using `!!` to
avoid integer overflow.

Fixes: #33
  • Loading branch information
illiliti committed Jun 25, 2021
1 parent bd7d180 commit bf23c9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion udev_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static void make_bit(unsigned long *arr, int cnt, const char *str)

static int test_bit(unsigned long *arr, unsigned long bit)
{
return arr[BIT_WORD(bit)] & BIT_MASK(bit);
return !!(arr[BIT_WORD(bit)] & BIT_MASK(bit));
}

static void set_properties_from_evdev(struct udev_device *udev_device)
Expand Down

0 comments on commit bf23c9e

Please sign in to comment.