On 2020-07-05 12:03:26 +0000, Mathieu Eyraud wrote:
Created attachment 4402
fix error checking and initialisation in SDL_hidapi.c
SDL dynamically loads libusb but does not check the return value of 'SDL_LoadFunction'.
Also libusb is loaded and initialized several time because 'SDL_hidapi_wasinit' is never set to true.
I made a patch if you want to test:
check that 'hid_init' is called once and only once,
check return value of 'hid_init',
check return value of 'SDL_LoadFunction',
check return value of 'SDL_malloc',
add some debug logging.
On 2020-07-05 12:22:48 +0000, Sven-Hendrik Haase wrote:
(In reply to meyraud705 from comment # 3)
Created attachment 4402 [details]
fix error checking and initialisation in SDL_hidapi.c
SDL dynamically loads libusb but does not check the return value of
'SDL_LoadFunction'.
Also libusb is loaded and initialized several time because
'SDL_hidapi_wasinit' is never set to true.
I made a patch if you want to test:
check that 'hid_init' is called once and only once,
check return value of 'hid_init',
check return value of 'SDL_LoadFunction',
check return value of 'SDL_malloc',
add some debug logging.
Doesn't compile for me:
FAILED: CMakeFiles/SDL2.dir/src/hidapi/SDL_hidapi.c.o
/usr/bin/cc -DSDL2_EXPORTS -DSDL_USE_IME -DUSING_GENERATED_CONFIG_H -Iinclude -I../include -Iwayland-generated-protocols -I/usr/include/libdrm -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/ibus-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -idirafter /build/sdl2/src/SDL2-2.0.12/src/video/khronos -I/usr/include/libusb-1.0 -I/build/sdl2/src/SDL2-2.0.12/src/hidapi/hidapi -DHAVE_LINUX_VERSION_H -I/usr/include/libdrm -I/usr/include -D_REENTRANT -msse3 -msse2 -msse -m3dnow -mmmx -Wshadow -fvisibility=hidden -Wdeclaration-after-statement -Werror=declaration-after-statement -fno-strict-aliasing -Wall -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fPIC -MD -MT CMakeFiles/SDL2.dir/src/hidapi/SDL_hidapi.c.o -MF CMakeFiles/SDL2.dir/src/hidapi/SDL_hidapi.c.o.d -o CMakeFiles/SDL2.dir/src/hidapi/SDL_hidapi.c.o -c ../src/hidapi/SDL_hidapi.c
In file included from ../src/hidapi/../SDL_internal.h:45,
from ../src/hidapi/SDL_hidapi.c:31:
../src/hidapi/SDL_hidapi.c: In function ‘hid_init’:
../src/hidapi/../dynapi/SDL_dynapi_overrides.h:35:21: warning: implicit declaration of function ‘SDL_LogWarn_REAL’; did you mean ‘SDL_CondWait_REAL’? [-Wimplicit-function-declaration]
35 | #define SDL_LogWarn SDL_LogWarn_REAL
| ^~~~~~~~~~~~~~~~
../src/hidapi/SDL_hidapi.c:501:13: note: in expansion of macro ‘SDL_LogWarn’
501 | SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function.");
| ^~~~~~~~~~~
../src/hidapi/SDL_hidapi.c:501:25: error: ‘SDL_LOG_CATEGORY_INPUT’ undeclared (first use in this function)
501 | SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function.");
| ^~~~~~~~~~~~~~~~~~~~~~
On 2020-07-06 09:01:48 +0000, Mathieu Eyraud wrote:
Created attachment 4403
fix error checking and initialisation in SDL_hidapi.c (no log)
Same patch with problematic line commented out (you will not get logging in case SDL_LoadFunction fail).
I don't understand why it doesn't compile for you. SDL_hidapi.c includes SDL_internals.h which include SDL_Log.h, and SDL_log.h defines SDL_LOG_CATEGORY_INPUT.
On 2020-07-06 10:28:31 +0000, Sven-Hendrik Haase wrote:
That seems to be working well for me, cool!
On 2020-07-10 23:01:23 +0000, Sven-Hendrik Haase wrote:
A user reports that while it doesn't crash, it also doesn't work. I'll try to get them to participate here.
On 2020-07-13 20:06:24 +0000, Dom wrote:
This looks like an important patch to make using HIDAPI less risky
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
fix error checking and initialisation in SDL_hidapi.c (hidapi_error_check.patch, text/plain, 2020-07-05 12:03:26 +0000, 5447 bytes)Reported in version: HG 2.0
Reported for operating system, platform: Linux, x86_64
Comments on the original bug report:
On 2020-07-03 10:06:09 +0000, Sven-Hendrik Haase wrote:
On 2020-07-03 10:07:14 +0000, Sven-Hendrik Haase wrote:
On 2020-07-03 10:09:50 +0000, Sven-Hendrik Haase wrote:
On 2020-07-05 12:03:26 +0000, Mathieu Eyraud wrote:
On 2020-07-05 12:22:48 +0000, Sven-Hendrik Haase wrote:
On 2020-07-06 09:01:48 +0000, Mathieu Eyraud wrote:
On 2020-07-06 10:28:31 +0000, Sven-Hendrik Haase wrote:
On 2020-07-10 23:01:23 +0000, Sven-Hendrik Haase wrote:
On 2020-07-13 20:06:24 +0000, Dom wrote:
On 2020-12-09 03:04:31 +0000, Sam Lantinga wrote:
The text was updated successfully, but these errors were encountered: