diff options
author | Joshua M. Clulow <josh@sysmgr.org> | 2023-07-06 11:22:55 -0700 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2023-07-07 13:33:02 +0200 |
commit | 681a8514454b0c876f30d13aa26465ff02c5c3a9 (patch) | |
tree | 22f26ab22866bca0417c56b94350d36b0b42f762 | |
parent | 7218b0dcc680aa7399dbe3515909d784daed68ad (diff) | |
download | libusb-681a8514454b0c876f30d13aa26465ff02c5c3a9.tar.gz |
sunos: Return error if OS paths hit their limits
Closes #1174
-rw-r--r-- | libusb/os/sunos_usb.c | 23 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 18 insertions, 7 deletions
diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c index 7c2f615..9c08f7e 100644 --- a/libusb/os/sunos_usb.c +++ b/libusb/os/sunos_usb.c @@ -1,6 +1,6 @@ /* - * * Copyright (c) 2016, Oracle and/or its affiliates. + * Copyright 2023 Oxide Computer Company * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -831,7 +831,7 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, { char filename[PATH_MAX + 1], statfilename[PATH_MAX + 1]; char cfg_num[16], alt_num[16]; - int fd, fdstat, mode; + int fd, fdstat, mode, e; uint8_t ifc = 0; uint8_t ep_index; sunos_dev_handle_priv_t *hpriv; @@ -870,11 +870,22 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, bzero(alt_num, sizeof(alt_num)); } - (void) snprintf(filename, PATH_MAX, "%s/%sif%d%s%s%d", + e = snprintf(filename, sizeof (filename), "%s/%sif%d%s%s%d", hpriv->dpriv->ugenpath, cfg_num, ifc, alt_num, - (ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? "in" : - "out", (ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK)); - (void) snprintf(statfilename, PATH_MAX, "%sstat", filename); + (ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? "in" : "out", + ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK); + if (e < 0 || e >= (int)sizeof (filename)) { + usbi_dbg(HANDLE_CTX(hdl), + "path buffer overflow for endpoint 0x%02x", ep_addr); + return (EINVAL); + } + + e = snprintf(statfilename, sizeof (statfilename), "%sstat", filename); + if (e < 0 || e >= (int)sizeof (statfilename)) { + usbi_dbg(HANDLE_CTX(hdl), + "path buffer overflow for endpoint 0x%02x stat", ep_addr); + return (EINVAL); + } /* * In case configuration has been switched, the xfer endpoint needs diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 73daa29..565f1d7 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11802 +#define LIBUSB_NANO 11803 |