[Patch] gutenprint53+usb crashes with libusb-1.0.25

Zdenek Dohnal <[email protected]>
Newsgroups gmane.linux.printing.gimp-print.devel
Message-ID <[email protected]>
Hi all,

there were changes in libusb 1.0.25 which is in Fedora 36 - f.e. default 
USB context is not initialized unless you specifically pass NULL into 
`libusb_init()` - gutenprint53+usb backend actually depended on this 
hidden behavior, because it passes its own context address into 
`libusb_init()` instead of NULL. So the change causes the backend to 
crash if you run it:

=======================================

$ sudo /usr/lib/cups/backend/gutenprint53+usb

DEBUG: Multi-Call Dye-sublimation CUPS Backend version 0.110G
DEBUG: Copyright 2007-2020 Solomon Peachy
DEBUG: This free software comes with ABSOLUTELY NO WARRANTY!
DEBUG: Licensed under the GNU GPL.  Run with '-G' for more details.

...

DEBUG:         [ -R ]           # Reset printer
DEBUG:         [ -s ]           # Query printer status
STATE: +org.gutenprint.searching-for-device
Segmentation fault

========================================

The backtrace is available in the related bugzilla [1].

According libusb maintainer, Ben Berg, the backend can work with the 
default USB context and he prepared the patch for it (the file is 
attached). I was able to verify the patch fixes the crash, but I don't 
have a device supported by gutenprint itself, so I couldn't do an 
additional sanity testing. The patch looks good to me though.

Would you mind adding the patch to the project if it looks good for you?


Thank you in advance!


Zdenek


[1] https://bugzilla.redhat.com/show_bug.cgi?id=2055504

-- 
Zdenek Dohnal
Software Engineer
Red Hat, BRQ-TPBC

_______________________________________________
Gimp-print-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gimp-print-devel
gutenprint-libusb-crash.patch (text/x-patch, 2.4 KB)
diff --git a/src/cups/backend_common.c b/src/cups/backend_common.c
index 6333408..b19668d 100644
--- a/src/cups/backend_common.c
+++ b/src/cups/backend_common.c
@@ -753,8 +753,7 @@ static struct dyesub_backend *backends[] = {
 	NULL,
 };
 
-static int find_and_enumerate(struct libusb_context *ctx,
-			      struct libusb_device ***list,
+static int find_and_enumerate(struct libusb_device ***list,
 			      const struct dyesub_backend *backend,
 			      const char *match_serno,
 			      const char *make,
@@ -777,7 +776,7 @@ static int find_and_enumerate(struct libusb_context *ctx,
 	STATE("+org.gutenprint.searching-for-device\n");
 
 	/* Enumerate and find suitable device */
-	num = libusb_get_device_list(ctx, list);
+	num = libusb_get_device_list(NULL, list);
 
 	/* See if we can actually match on the supplied make! */
 	if (backend && make) {
@@ -1010,7 +1009,6 @@ along with this program; if not, see <https://www.gnu.org/licenses/>.\n\n";
 
 void print_help(const char *argv0, const struct dyesub_backend *backend)
 {
-	struct libusb_context *ctx = NULL;
 	struct libusb_device **list = NULL;
 
 	const char *ptr = getenv("BACKEND");
@@ -1072,7 +1070,7 @@ void print_help(const char *argv0, const struct dyesub_backend *backend)
 	}
 
 	/* Scan for all printers for the specified backend */
-	find_and_enumerate(ctx, &list, backend, NULL, ptr, 1, 1, NULL);
+	find_and_enumerate(&list, backend, NULL, ptr, 1, 1, NULL);
 	libusb_free_device_list(list, 1);
 }
 
@@ -1251,7 +1249,6 @@ done:
 
 int main (int argc, char **argv)
 {
-	struct libusb_context *ctx = NULL;
 	struct libusb_device **list = NULL;
 
 	struct dyesub_backend *backend = NULL;
@@ -1414,7 +1411,7 @@ int main (int argc, char **argv)
 #endif
 
 	/* Libusb setup */
-	ret = libusb_init(&ctx);
+	ret = libusb_init(NULL);
 	if (ret) {
 		ERROR("Failed to initialize libusb (%d)\n", ret);
 		ret = CUPS_BACKEND_RETRY_CURRENT;
@@ -1438,7 +1435,7 @@ int main (int argc, char **argv)
 	}
 
 	/* Enumerate devices */
-	found = find_and_enumerate(ctx, &list, backend, use_serno, backend_str, 0, NUM_CLAIM_ATTEMPTS, &conn);
+	found = find_and_enumerate(&list, backend, use_serno, backend_str, 0, NUM_CLAIM_ATTEMPTS, &conn);
 
 	if (found == -1) {
 		ERROR("Printer open failure (No matching printers found!)\n");
@@ -1572,7 +1569,7 @@ done:
 	if (list)
 		libusb_free_device_list(list, 1);
 
-	libusb_exit(ctx);
+	libusb_exit(NULL);
 
 	return ret;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.