diff options
author | Aurelien Jarno <aurelien@aurel32.net> | 2023-12-11 22:07:17 +0100 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2023-12-11 23:26:09 +0100 |
commit | ebfbf195d459b83d5f2e96a8663c953087f3eb0f (patch) | |
tree | 591d927cc7274326c93966f101205d91f67232c2 | |
parent | cc3df7760926bd98358e3d2c76c1511fe7861365 (diff) | |
download | libusb-ebfbf195d459b83d5f2e96a8663c953087f3eb0f.tar.gz |
tests/set_option: Avoid use-after-free in case of test failure
In case num_devices equals 0, LIBUSB_EXPECT() calls
LIBUSB_TEST_CLEAN_EXIT(), which calls libusb_exit() on test_ctx which
has just been freed a few lines above by a call to libusb_exit(). This
might cause a SEGFAULT or SIGBUS depending on the system.
Fixes that by assigning NULL to test_ctx just after calling
libusb_exit() like it is done elsewhere in the file.
Closes #1374
-rw-r--r-- | libusb/version_nano.h | 2 | ||||
-rw-r--r-- | tests/set_option.c | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 7dc487b..3dfc13c 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11848 +#define LIBUSB_NANO 11849 diff --git a/tests/set_option.c b/tests/set_option.c index c983378..20c55eb 100644 --- a/tests/set_option.c +++ b/tests/set_option.c @@ -174,6 +174,7 @@ static libusb_testlib_result test_no_discovery(void) ssize_t num_devices = libusb_get_device_list(test_ctx, &device_list); libusb_free_device_list(device_list, /*unref_devices=*/1); libusb_exit(test_ctx); + test_ctx = NULL; LIBUSB_EXPECT(>, num_devices, 0); |