{
struct dirent **namelist;
int ndev, i;
+ int rc;
+ char buf[sizeof(SYS_INPUT_DIR) + 64];
/* FIXME: use new ioctl() here once kernel supports it */
for (i = 0; i < ndev; i++) {
int fd, len;
- char buf[sizeof(SYS_INPUT_DIR) + 64];
struct stat st;
- strcpy(buf, SYS_INPUT_DIR);
- strcat(buf, namelist[i]->d_name);
+ rc = snprintf(buf, sizeof(buf), "%s%s/name",
+ SYS_INPUT_DIR,
+ namelist[i]->d_name);
+ if (rc < 0 || (size_t)rc >= sizeof(buf)) {
+ continue;
+ }
if (stat(buf, &st) == -1)
continue;
continue;
/* created within time frame */
- strcat(buf, "/name");
fd = open(buf, O_RDONLY);
if (fd < 0)
continue;
log_info("multiple identical devices found. syspath is unreliable\n");
break;
} else {
- strcpy(buf, SYS_INPUT_DIR);
- strcat(buf, namelist[i]->d_name);
+ rc = snprintf(buf, sizeof(buf), "%s%s",
+ SYS_INPUT_DIR,
+ namelist[i]->d_name);
+ if (rc < 0 || (size_t)rc >= sizeof(buf)) {
+ log_error("Invalid syspath, syspath is unreliable\n");
+ break;
+ }
+
uinput_dev->syspath = strdup(buf);
uinput_dev->devnode = fetch_device_node(buf);
}