summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg V <greg@unrelenting.technology>2018-10-14 15:15:15 +0300
committerGreg V <greg@unrelenting.technology>2018-10-16 13:01:02 +0300
commitb0cd07bf753f7621c75ead1812a7bf97a2e86a55 (patch)
tree75b66df58447cb614389ffdf645c431e34587083
parent430ede82666b7b689d5f19dde4817f5d28bc14f6 (diff)
downloadlibinput-b0cd07bf753f7621c75ead1812a7bf97a2e86a55.tar.gz
quirks: use basename in a POSIX compliant way
The POSIX version of basename modifies the string (and therefore crashes on static strings), so use safe_strdup before calling it. glibc provides a POSIX version when libgen.h is included. FreeBSD 12 provides a POSIX version when nothing is included, which was causing a segfault. Using the POSIX version correctly is the right way to avoid any such issues.
-rw-r--r--src/quirks.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/quirks.c b/src/quirks.c
index a65ce4fb..8b400fb7 100644
--- a/src/quirks.c
+++ b/src/quirks.c
@@ -34,6 +34,7 @@
#include <libudev.h>
#include <dirent.h>
#include <fnmatch.h>
+#include <libgen.h>
#include "libinput-versionsort.h"
#include "libinput-util.h"
@@ -413,7 +414,9 @@ section_new(const char *path, const char *name)
{
struct section *s = zalloc(sizeof(*s));
- xasprintf(&s->name, "%s (%s)", name, basename(path));
+ char *path_dup = safe_strdup(path);
+ xasprintf(&s->name, "%s (%s)", name, basename(path_dup));
+ free(path_dup);
list_init(&s->link);
list_init(&s->properties);