
Fix below UBSAN reports, thrown on sandbox:
============================================================ UBSAN: Undefined behaviour in drivers/input/input.c:512:7 variable length array bound value 0 <= 0 ============================================================ ============================================================ UBSAN: Undefined behaviour in drivers/input/input.c:340:6 variable length array bound value 0 <= 0 ============================================================
Inspired from Linux v4.11-rc1 commit 620711944459 ("crypto: algif_hash - avoid zero-sized array").
Fixes: 9bc590e5119f ("input: Add generic keyboard input handler") Signed-off-by: Eugeniu Rosca erosca@de.adit-jv.com ---
Changes in v2: - None. Newly pushed. --- drivers/input/input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/input.c b/drivers/input/input.c index 29620a9e2793..a8fd197883aa 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -337,7 +337,7 @@ static int array_search(int *array, int count, int key) static int sort_array_by_ordering(int *dest, int count, int *order, int ocount) { - int temp[count]; + int temp[count ? : 1]; int dest_count; int same; /* number of elements which are the same */ int i; @@ -509,7 +509,7 @@ static int input_keycodes_to_ascii(struct input_config *config, static int _input_send_keycodes(struct input_config *config, int keycode[], int num_keycodes, bool do_send) { - char ch[num_keycodes * ANSI_CHAR_MAX]; + char ch[(num_keycodes * ANSI_CHAR_MAX) ? : 1]; int count, i, same = 0; int is_repeat = 0; unsigned delay_ms;