summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2022-06-17 19:01:37 -0400
committerTormod Volden <debian.tormod@gmail.com>2022-06-26 17:09:14 +0200
commitfa9a25b3c47420fe4fbafea83b865516b1f10aea (patch)
treebab5b0a85b70114dff57abc3955dd786e9bfefa2
parent347d21a385898828150c00648e714cec0a25baab (diff)
downloadlibusb-fa9a25b3c47420fe4fbafea83b865516b1f10aea.tar.gz
examples: Replace most uses of sprintf with safer snprintf
Closes #1155
-rw-r--r--examples/dpfp.c2
-rw-r--r--libusb/os/linux_usbfs.c8
-rw-r--r--libusb/version_nano.h2
3 files changed, 6 insertions, 6 deletions
diff --git a/examples/dpfp.c b/examples/dpfp.c
index 6828650..ac43dac 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -53,7 +53,7 @@ static inline semaphore_t semaphore_create(void)
sem_t *semaphore;
char name[50];
- sprintf(name, "/org.libusb.example.dpfp_threaded:%d", (int)getpid());
+ snprintf(name, sizeof(name), "/org.libusb.example.dpfp_threaded:%d", (int)getpid());
semaphore = sem_open(name, O_CREAT | O_EXCL, 0, 0);
if (semaphore == SEM_FAILED)
return NULL;
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 285d9ca..1ebe36c 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -187,10 +187,10 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
int fd;
if (usbdev_names)
- sprintf(path, USBDEV_PATH "/usbdev%u.%u",
+ snprintf(path, sizeof(path), USBDEV_PATH "/usbdev%u.%u",
dev->bus_number, dev->device_address);
else
- sprintf(path, USB_DEVTMPFS_PATH "/%03u/%03u",
+ snprintf(path, sizeof(path), USB_DEVTMPFS_PATH "/%03u/%03u",
dev->bus_number, dev->device_address);
fd = open(path, mode | O_CLOEXEC);
@@ -597,7 +597,7 @@ int linux_get_device_address(struct libusb_context *ctx, int detached,
char proc_path[32];
/* try to retrieve the device node from fd */
- sprintf(proc_path, "/proc/self/fd/%d", fd);
+ snprintf(proc_path, sizeof(proc_path), "/proc/self/fd/%d", fd);
r = readlink(proc_path, fd_path, PATH_MAX - 1);
if (r > 0) {
fd_path[r] = '\0';
@@ -1188,7 +1188,7 @@ static int usbfs_scan_busdir(struct libusb_context *ctx, uint8_t busnum)
struct dirent *entry;
int r = LIBUSB_ERROR_IO;
- sprintf(dirpath, USB_DEVTMPFS_PATH "/%03u", busnum);
+ snprintf(dirpath, sizeof(dirpath), USB_DEVTMPFS_PATH "/%03u", busnum);
usbi_dbg(ctx, "%s", dirpath);
dir = opendir(dirpath);
if (!dir) {
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9c6ce1e..045fb83 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11729
+#define LIBUSB_NANO 11730