From 420fa2a8a4dd7294d0b23696103d7887ae570e43 Mon Sep 17 00:00:00 2001 From: Niclas Zeising Date: Wed, 11 Sep 2019 22:30:16 +0200 Subject: Fix segfault when tags file isn't found Fix a segfault when the tags file isn't found. xedit tries to construct a path to the tags file (by defailt ${HOME}/tags), using amongst other things basename(3). However, basename is called with an immutable string which causes segfaults on FreeBSD, since basename(3) uses the provided buffer to store it's result. Change the code to duplicate the string with strdup() and call basename on the duplicated string instead. --- util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index bbc8ea9..5471129 100644 --- a/util.c +++ b/util.c @@ -506,13 +506,14 @@ ResolveName(char *filename) if (result == NULL && errno == ENOENT) { int length; - char *dir, *file; + char *dir, *file, *fname; length = strlen(filename); tmp = dir = XtMalloc(length + 1); strcpy(dir, filename); + fname = strdup(filename); - file = basename(filename); + file = basename(fname); dir = dirname(tmp); /* Creating a new file? */ @@ -526,6 +527,7 @@ ResolveName(char *filename) } XtFree(tmp); + free(fname); } return (result); -- cgit v1.2.3