From ce2fbbdbe22f602dea1bde497ef1694e4fb89033 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 30 Nov 2016 05:12:28 +0100 Subject: [PATCH] (hid_joypad.c) Prevent null pointer dereferences --- input/drivers_joypad/hid_joypad.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/input/drivers_joypad/hid_joypad.c b/input/drivers_joypad/hid_joypad.c index 1340638f24..fb504698da 100644 --- a/input/drivers_joypad/hid_joypad.c +++ b/input/drivers_joypad/hid_joypad.c @@ -18,7 +18,7 @@ #include "../input_hid_driver.h" #include "../input_driver.h" -static const hid_driver_t *generic_hid; +static const hid_driver_t *generic_hid = NULL; static bool hid_joypad_init(void *data) { @@ -33,7 +33,9 @@ static bool hid_joypad_init(void *data) static bool hid_joypad_query_pad(unsigned pad) { - return generic_hid->query_pad((void*)hid_driver_get_data(), pad); + if (generic_hid && generic_hid->query_pad) + return generic_hid->query_pad((void*)hid_driver_get_data(), pad); + return false; } static void hid_joypad_free(void) @@ -49,28 +51,37 @@ static void hid_joypad_free(void) static bool hid_joypad_button(unsigned port, uint16_t joykey) { - return generic_hid->button((void*)hid_driver_get_data(), port, joykey); + if (generic_hid && generic_hid->button) + return generic_hid->button((void*)hid_driver_get_data(), port, joykey); + return false; } static uint64_t hid_joypad_get_buttons(unsigned port) { - return generic_hid->get_buttons((void*)hid_driver_get_data(), port); + if (generic_hid && generic_hid->get_buttons) + return generic_hid->get_buttons((void*)hid_driver_get_data(), port); + return 0; } static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis) { - return generic_hid->axis((void*)hid_driver_get_data(), port, joyaxis); + if (generic_hid && generic_hid->axis) + return generic_hid->axis((void*)hid_driver_get_data(), port, joyaxis); + return 0; } static void hid_joypad_poll(void) { - generic_hid->poll((void*)hid_driver_get_data()); + if (generic_hid && generic_hid->poll) + generic_hid->poll((void*)hid_driver_get_data()); } static bool hid_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) { - return generic_hid->set_rumble((void*)hid_driver_get_data(), pad, effect, strength); + if (generic_hid && generic_hid->set_rumble) + return generic_hid->set_rumble((void*)hid_driver_get_data(), pad, effect, strength); + return false; } static const char *hid_joypad_name(unsigned pad)