components/libusb-1/patches/02-libusb.patch
author Raymond Chen <Raymond.Chen@Oracle.COM>
Tue, 26 Apr 2016 18:36:36 -0700
changeset 5851 9f4a6f531294
permissions -rw-r--r--
22978185 libusb 1.0 manpage 23008017 invalid free in sunos_async_callback() in libusb

Fix unnecessary free(), active config value and descriptor, and identifier.

--- libusb-1.0.20/libusb/os/sunos_usb.h	2016-04-06 20:05:55.785721970 -0700
+++ libusb/libusb/os/sunos_usb.h	2016-04-06 20:02:21.487553309 -0700
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef	__SUNOS_H__
-#define	__SUNOS_H__
+#ifndef	LIBUSB_SUNOS_H
+#define	LIBUSB_SUNOS_H
 
 #include <libdevinfo.h>
 #include <pthread.h>
@@ -71,4 +71,4 @@
 	struct aiocb aiocb;
 };
 
-#endif /* __SUNOS_H__ */
+#endif /* LIBUSB_SUNOS_H */
--- libusb-1.0.20/libusb/os/sunos_usb.c	2016-04-06 20:05:55.785428005 -0700
+++ libusb/libusb/os/sunos_usb.c	2016-04-06 20:02:21.487451492 -0700
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -122,6 +122,8 @@
 		return (LIBUSB_ERROR_NO_MEM);
 	} else {
 		bcopy(rdata, dpriv->raw_cfgdescr, proplen);
+		dpriv->cfgvalue = ((struct libusb_config_descriptor *)
+		    rdata)->bConfigurationValue;
 	}
 
 	n = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &port_prop);
@@ -651,12 +653,40 @@
 {
 	sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
 	struct libusb_config_descriptor *cfg;
+	int proplen;
+	di_node_t node;
+	uint8_t	*rdata;
+
+	/*
+	 * Keep raw configuration descriptors updated, in case config
+	 * has ever been changed through setCfg.
+	 */
+	if ((node = di_init(dpriv->phypath, DINFOCPYALL)) == DI_NODE_NIL) {
+		usbi_dbg("di_int() failed: %s", strerror(errno));
+		return (LIBUSB_ERROR_IO);
+	}
+	proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
+	    "usb-raw-cfg-descriptors", &rdata);
+	if (proplen <= 0) {
+		usbi_dbg("can't find raw config descriptors");
+
+		return (LIBUSB_ERROR_IO);
+	}
+	dpriv->raw_cfgdescr = realloc(dpriv->raw_cfgdescr, proplen);
+	if (dpriv->raw_cfgdescr == NULL) {
+		return (LIBUSB_ERROR_NO_MEM);
+	} else {
+		bcopy(rdata, dpriv->raw_cfgdescr, proplen);
+		dpriv->cfgvalue = ((struct libusb_config_descriptor *)
+		    rdata)->bConfigurationValue;
+	}
+	di_fini(node);
 
 	cfg = (struct libusb_config_descriptor *)dpriv->raw_cfgdescr;
 	len = MIN(len, libusb_le16_to_cpu(cfg->wTotalLength));
 	memcpy(buf, dpriv->raw_cfgdescr, len);
 	*host_endian = 0;
-	usbi_dbg("len %d", len);
+	usbi_dbg("path:%s len %d", dpriv->phypath, len);
 
 	return (len);
 }
@@ -685,7 +715,10 @@
 sunos_set_configuration(struct libusb_device_handle *handle, int config)
 {
 	sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
+	sunos_dev_handle_priv_t *hpriv;
+
 	usbi_dbg("bConfigurationValue %d", config);
+	hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
 
 	if (dpriv->ugenpath == NULL)
 		return (LIBUSB_ERROR_NOT_SUPPORTED);
@@ -694,6 +727,7 @@
 		return (LIBUSB_ERROR_INVALID_PARAM);
 
 	dpriv->cfgvalue = config;
+	hpriv->config_index = config - 1;
 
 	return (LIBUSB_SUCCESS);
 }
@@ -797,7 +831,6 @@
 
 	/* async notification */
 	usbi_signal_transfer_completion(LIBUSB_TRANSFER_TO_USBI_TRANSFER(xfer));
-	free(aiocb);
 }
 
 static int