diff options
author | Niclas Zeising <zeising@daemonic.se> | 2019-09-11 22:30:16 +0200 |
---|---|---|
committer | Niclas Zeising <zeising@daemonic.se> | 2019-09-11 22:30:16 +0200 |
commit | 420fa2a8a4dd7294d0b23696103d7887ae570e43 (patch) | |
tree | dff3799d8b09e5e58695b1cc1ababd4e7196e5a6 | |
parent | abbacff9e01616f08c469637fa24132e151446f9 (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.
-rw-r--r-- | util.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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); |