The C Source, Patches and (shudder!) Bugs
Post Reply
otila
Posts: 6
Joined: 12 Feb 2015, 20:59

segfault

Post by otila » 12 Feb 2015, 22:12

usb_modeswitch-2.2.1
usb_modeswitch-data 20150115
libusbx-1.0.19-2.fc21

let me suggest that you check return value of libusb_get_active_config_descriptor.
and why does it check the global variable ret in get_current_configuration?
Core was generated by `/usr/sbin/usb_modeswitch -Q -D -s 20 -b 3 -g 9 -v 12d1 -p 157d -f Configuratio'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __GI___libc_free (mem=0x100544d48) at malloc.c:2934
2934 if (chunk_is_mmapped (p)) /* release mmapped memory. */
Missing separate debuginfos, use: debuginfo-install usb_modeswitch-2.2.1-1.fc21.x86_64
(gdb) bt
#0 __GI___libc_free (mem=0x100544d48) at malloc.c:2934
#1 0x00007f7886fbe833 in clear_configuration () from /lib64/libusb-1.0.so.0
#2 0x00007f7886fbfa3e in libusb_free_config_descriptor () from /lib64/libusb-1.0.so.0
#3 0x00000000004035e5 in get_current_configuration () at usb_modeswitch.c:1814
#4 0x0000000000406c8b in main (argc=<optimized out>, argv=<optimized out>) at usb_modeswitch.c:732
one funny thing: if I do this,

Code: Select all

-			case 'Q': show_progress = 0; verbose = 0; count--; break;
+			case 'Q': show_progress = 1; verbose = 0; count--; break;
I get this:
2015-02-12 21:45:36.944076920 [289236.845535] Read(10): 28 00 00 00 0f fe 00 00 02 00
2015-02-12 21:45:36.944077177 [289236.845547] blk_update_request: critical medium error, dev sr1, sector 16376
2015-02-12 21:45:36.962092834 [289236.863725] sr 55:0:0:0: [sr1] FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
2015-02-12 21:45:36.962093793 [289236.863728] sr 55:0:0:0: [sr1] Sense Key : Medium Error [current]
2015-02-12 21:45:36.962094150 [289236.863730] sr 55:0:0:0: [sr1] Add. Sense: Unrecovered read error
2015-02-12 21:45:36.962094462 [289236.863731] sr 55:0:0:0: [sr1] CDB:
okay, wasted two hours because of that.

okay, here fix for segfault

Code: Select all

--- usb_modeswitch.orig.c	2015-01-14 22:13:59.000000000 +0200
+++ usb_modeswitch.c	2015-02-12 21:51:11.556731968 +0200
@@ -575,6 +575,8 @@
 	} else
 		libusb_free_config_descriptor(active_config);
 
+	active_config = NULL;
+
 	if (interfaceClass == -1) {
 		fprintf(stderr, "Error: Could not get class of interface %d. Does it exist? Abort\n\n",Interface);
 		exit(1);
some extra checks

Code: Select all

--- usb_modeswitch.orig.c	2015-01-14 22:13:59.000000000 +0200
+++ usb_modeswitch.c	2015-02-12 21:57:42.648207760 +0200
@@ -1807,14 +1809,15 @@
 {
 	int cfg;
 	SHOW_PROGRESS(output,"Get the current device configuration ...\n");
-	if (active_config == NULL)
-		libusb_get_active_config_descriptor(dev, &active_config);
+	if (active_config == NULL) {
+		ret = libusb_get_active_config_descriptor(dev, &active_config);
+		if (ret < 0)
+			exit(1);
+	}
 
 	cfg = active_config->bConfigurationValue;
 	libusb_free_config_descriptor(active_config);
-	if (ret < 0)
-		exit(1);
-	else
+	active_config = NULL;
 		return cfg;
 }
 
not that I understand why you have to use global variables like that :cry:

Josh
Site Admin
Posts: 6570
Joined: 03 Nov 2007, 00:30

Re: segfault

Post by Josh » 13 Feb 2015, 18:48

Thank you, I will certainly consider your suggestions.

Since C is not my 'native' programming language, there may well be some sloppiness involved.

Post Reply