summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-02-18 14:06:03 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-02-23 10:56:53 +1000
commitca9067992e33be3a5fc9da735828cb6188239bf1 (patch)
tree9870fc1c5ff1eb02f120bb63eaaf4ee3598cfa97
parent671eb8cbbb4dc5c88d38c935c176d61604154584 (diff)
downloadlibinput-ca9067992e33be3a5fc9da735828cb6188239bf1.tar.gz
tools/record: use safe_basename() to get to the hid report descriptor
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--tools/libinput-record.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/tools/libinput-record.c b/tools/libinput-record.c
index d95e2b91..db787cc4 100644
--- a/tools/libinput-record.c
+++ b/tools/libinput-record.c
@@ -1724,7 +1724,6 @@ print_hid_report_descriptor(struct record_context *ctx,
struct record_device *dev)
{
const char *prefix = "/dev/input/event";
- const char *node;
char syspath[PATH_MAX];
unsigned char buf[1024];
int len;
@@ -1733,18 +1732,16 @@ print_hid_report_descriptor(struct record_context *ctx,
/* we take the shortcut rather than the proper udev approach, the
report_descriptor is available in sysfs and two devices up from
- our device. 2 digits for the event number should be enough.
+ our device.
This approach won't work for /dev/input/by-id devices. */
- if (!strstartswith(dev->devnode, prefix) ||
- strlen(dev->devnode) > strlen(prefix) + 2)
+ if (!strstartswith(dev->devnode, prefix))
return;
- node = &dev->devnode[strlen(prefix)];
len = snprintf(syspath,
sizeof(syspath),
- "/sys/class/input/event%s/device/device/report_descriptor",
- node);
- if (len < 55 || len > 56)
+ "/sys/class/input/%s/device/device/report_descriptor",
+ safe_basename(dev->devnode));
+ if (len <= 0)
return;
fd = open(syspath, O_RDONLY);