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>
This commit is contained in:
Stefan Richter 2009-05-31 00:25:52 +02:00
parent 489981d4ae
commit 5824e34d08
1 changed files with 10 additions and 4 deletions

View File

@ -9,6 +9,7 @@
* details.
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@ -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);