summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/evdev.c31
-rw-r--r--src/evdev.h6
-rw-r--r--src/util-strings.h30
3 files changed, 55 insertions, 12 deletions
diff --git a/src/evdev.c b/src/evdev.c
index d8dfdadd..0b4b3590 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -2291,19 +2291,19 @@ evdev_device_create(struct libinput_seat *seat,
struct libinput *libinput = seat->libinput;
struct evdev_device *device = NULL;
int rc;
- int fd;
+ int fd = -1;
int unhandled_device = 0;
const char *devnode = udev_device_get_devnode(udev_device);
- const char *sysname = udev_device_get_sysname(udev_device);
+ char *sysname = str_sanitize(udev_device_get_sysname(udev_device));
if (!devnode) {
log_info(libinput, "%s: no device node associated\n", sysname);
- return NULL;
+ goto err;
}
if (udev_device_should_be_ignored(udev_device)) {
log_debug(libinput, "%s: device is ignored\n", sysname);
- return NULL;
+ goto err;
}
/* Use non-blocking mode so that we can loop on read on
@@ -2317,13 +2317,15 @@ evdev_device_create(struct libinput_seat *seat,
sysname,
devnode,
strerror(-fd));
- return NULL;
+ goto err;
}
if (!evdev_device_have_same_syspath(udev_device, fd))
goto err;
device = zalloc(sizeof *device);
+ device->sysname = sysname;
+ sysname = NULL;
libinput_device_init(&device->base, seat);
libinput_seat_ref(seat);
@@ -2346,6 +2348,9 @@ evdev_device_create(struct libinput_seat *seat,
device->dispatch = NULL;
device->fd = fd;
device->devname = libevdev_get_name(device->evdev);
+ /* the log_prefix_name is used as part of a printf format string and
+ * must not contain % directives, see evdev_log_msg */
+ device->log_prefix_name = str_sanitize(device->devname);
device->scroll.threshold = 5.0; /* Default may be overridden */
device->scroll.direction_lock_threshold = 5.0; /* Default may be overridden */
device->scroll.direction = 0;
@@ -2386,12 +2391,16 @@ evdev_device_create(struct libinput_seat *seat,
return device;
err:
- close_restricted(libinput, fd);
- if (device) {
- unhandled_device = device->seat_caps == 0;
- evdev_device_destroy(device);
+ if (fd >= 0) {
+ close_restricted(libinput, fd);
+ if (device) {
+ unhandled_device = device->seat_caps == 0;
+ evdev_device_destroy(device);
+ }
}
+ free(sysname);
+
return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL;
}
@@ -2404,7 +2413,7 @@ evdev_device_get_output(struct evdev_device *device)
const char *
evdev_device_get_sysname(struct evdev_device *device)
{
- return udev_device_get_sysname(device->udev_device);
+ return device->sysname;
}
const char *
@@ -3001,6 +3010,8 @@ evdev_device_destroy(struct evdev_device *device)
if (device->base.group)
libinput_device_group_unref(device->base.group);
+ free(device->log_prefix_name);
+ free(device->sysname);
free(device->output_name);
filter_destroy(device->pointer.filter);
libinput_timer_destroy(&device->scroll.timer);
diff --git a/src/evdev.h b/src/evdev.h
index c7d130f8..980c5943 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -169,6 +169,8 @@ struct evdev_device {
struct udev_device *udev_device;
char *output_name;
const char *devname;
+ char *log_prefix_name;
+ char *sysname;
bool was_removed;
int fd;
enum evdev_device_seat_capability seat_caps;
@@ -786,7 +788,7 @@ evdev_log_msg(struct evdev_device *device,
sizeof(buf),
"%-7s - %s%s%s",
evdev_device_get_sysname(device),
- (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->devname : "",
+ (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "",
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "",
format);
@@ -824,7 +826,7 @@ evdev_log_msg_ratelimit(struct evdev_device *device,
sizeof(buf),
"%-7s - %s%s%s",
evdev_device_get_sysname(device),
- (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->devname : "",
+ (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "",
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "",
format);
diff --git a/src/util-strings.h b/src/util-strings.h
index 2a15fab3..d5a84146 100644
--- a/src/util-strings.h
+++ b/src/util-strings.h
@@ -43,6 +43,8 @@
#include <xlocale.h>
#endif
+#include "util-macros.h"
+
static inline bool
streq(const char *str1, const char *str2)
{
@@ -398,3 +400,31 @@ safe_basename(const char *filename);
char *
trunkname(const char *filename);
+
+/**
+ * Return a copy of str with all % converted to %% to make the string
+ * acceptable as printf format.
+ */
+static inline char *
+str_sanitize(const char *str)
+{
+ if (!str)
+ return NULL;
+
+ if (!strchr(str, '%'))
+ return strdup(str);
+
+ size_t slen = min(strlen(str), 512);
+ char *sanitized = zalloc(2 * slen + 1);
+ const char *src = str;
+ char *dst = sanitized;
+
+ for (size_t i = 0; i < slen; i++) {
+ if (*src == '%')
+ *dst++ = '%';
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+
+ return sanitized;
+}