From 5824e34d08491dd80d6ec6f500c29c6b52a48a1a Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 31 May 2009 00:25:52 +0200 Subject: [PATCH] Match only /dev/fw[0-9]* as firewire-core device files Previously, /dev/fw* and hence files like /dev/fwmonitor were probed which may have bad effects if the client runs with access privileges. Signed-off-by: Stefan Richter --- src/fw.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fw.c b/src/fw.c index fc4908e..d63d0da 100644 --- a/src/fw.c +++ b/src/fw.c @@ -9,6 +9,7 @@ * details. */ +#include #include #include #include @@ -107,6 +108,13 @@ default_bus_reset_handler(raw1394handle_t handle, unsigned int gen) return 0; } +static int +is_fw_device_name(char *name) +{ + return strncmp(name, FW_DEVICE_PREFIX, strlen(FW_DEVICE_PREFIX)) == 0 + && isdigit(name[strlen(FW_DEVICE_PREFIX)]); +} + static int scan_devices(fw_handle_t handle) { @@ -132,8 +140,7 @@ scan_devices(fw_handle_t handle) if (de == NULL) break; - if (strncmp(de->d_name, - FW_DEVICE_PREFIX, strlen(FW_DEVICE_PREFIX)) != 0) + if (!is_fw_device_name(de->d_name)) continue; snprintf(filename, sizeof filename, FW_DEVICE_DIR "/%s", de->d_name); @@ -327,8 +334,7 @@ handle_inotify(raw1394handle_t handle, struct epoll_closure *ec, len = read(fwhandle->inotify_fd, event, BUFFER_SIZE); if (!(event->mask & IN_CREATE)) return -1; - if (strncmp(event->name, - FW_DEVICE_PREFIX, strlen(FW_DEVICE_PREFIX)) != 0) + if (!is_fw_device_name(event->name)) return 0; snprintf(filename, sizeof filename, FW_DEVICE_DIR "/%s", event->name); fd = open(filename, O_RDWR);