diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2009-05-31 00:25:52 +0200 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2009-05-31 00:30:33 +0200 |
commit | 5824e34d08491dd80d6ec6f500c29c6b52a48a1a (patch) | |
tree | c3a78d3b9cee863f5f68e55195a6ad721f5b0e6f | |
parent | 489981d4ae905127a0f7c300e7d12161666fc0c8 (diff) | |
download | libraw1394-5824e34d08491dd80d6ec6f500c29c6b52a48a1a.tar.gz |
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 <stefanr@s5r6.in-berlin.de>
-rw-r--r-- | src/fw.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -9,6 +9,7 @@ * details. */ +#include <ctype.h> #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -108,6 +109,13 @@ default_bus_reset_handler(raw1394handle_t handle, unsigned int gen) } 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) { DIR *dir; @@ -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); |