aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2015-07-11 18:06:22 +0200
committerGuy Harris <guy@alum.mit.edu>2015-07-11 18:18:35 +0000
commita68518f4996310792860628b5f860d0005cd4f6a (patch)
tree7755da5079308431a6af5c65923993bdfdaa0eb7 /wsutil
parente47826734e9d3d6ca2c3589883ff62fce08e7339 (diff)
terminate readlink result
The readlink function does not guarantee to nul-terminate its result string. Therefore, it should be done in wsutil/filesystem.c. Change-Id: Id96533e825a302a1922ce9ac7ee47d5525ac9c39 Reviewed-on: https://code.wireshark.org/review/9597 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/filesystem.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index 1006593730..daa44035f5 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -367,7 +367,8 @@ get_executable_path(void)
* XXX - are there OS versions that support "exe" but not "self"?
*/
struct utsname name;
- static char executable_path[PATH_MAX];
+ static char executable_path[PATH_MAX + 1];
+ ssize_t r;
if (uname(&name) == -1)
return NULL;
@@ -378,8 +379,9 @@ get_executable_path(void)
strcmp(name.release, "2.1") == 0 ||
strncmp(name.release, "2.1.", 4) == 0)
return NULL; /* Linux 2.0.x or 2.1.x */
- if (readlink("/proc/self/exe", executable_path, sizeof executable_path) == -1)
+ if ((r = readlink("/proc/self/exe", executable_path, PATH_MAX)) == -1)
return NULL;
+ executable_path[r] = '\0';
return executable_path;
#elif defined(__FreeBSD__) && defined(KERN_PROC_PATHNAME)
/*
@@ -417,10 +419,12 @@ get_executable_path(void)
* XXX - are there OS versions that support "exe" but not "curproc"
* or "self"? Are there any that support "self" but not "curproc"?
*/
- static char executable_path[PATH_MAX];
+ static char executable_path[PATH_MAX + 1];
+ ssize_t r;
- if (readlink("/proc/curproc/exe", executable_path, sizeof executable_path) == -1)
+ if ((r = readlink("/proc/curproc/exe", executable_path, PATH_MAX)) == -1)
return NULL;
+ executable_path[r] = '\0';
return executable_path;
#elif defined(__DragonFly__)
/*
@@ -429,10 +433,12 @@ get_executable_path(void)
* instead; it appears to be supported by all versions of DragonFly
* BSD.
*/
- static char executable_path[PATH_MAX];
+ static char executable_path[PATH_MAX + 1];
+ ssize_t r;
- if (readlink("/proc/curproc/file", executable_path, sizeof executable_path) == -1)
+ if ((r = readlink("/proc/curproc/file", executable_path, PATH_MAX)) == -1)
return NULL;
+ executable_path[r] = '\0';
return executable_path;
#elif (defined(sun) || defined(__sun)) && defined(HAVE_GETEXECNAME)
/*