summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNiclas Zeising <zeising@daemonic.se>2019-09-11 22:30:16 +0200
committerNiclas Zeising <zeising@daemonic.se>2019-09-11 22:30:16 +0200
commit420fa2a8a4dd7294d0b23696103d7887ae570e43 (patch)
treedff3799d8b09e5e58695b1cc1ababd4e7196e5a6 /util.c
parentabbacff9e01616f08c469637fa24132e151446f9 (diff)
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.
Diffstat (limited to 'util.c')
-rw-r--r--util.c6
1 files changed, 4 insertions, 2 deletions
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);