aboutsummaryrefslogtreecommitdiff
path: root/gdb/fbsd-nat.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2018-01-09 13:35:17 -0800
committerJohn Baldwin <jhb@FreeBSD.org>2018-01-09 13:35:17 -0800
commitb999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a (patch)
tree611e13c2ebffc3ec8d90218c327f231bb73a1812 /gdb/fbsd-nat.c
parentd2176225dc982c22640215a0e611e997e8eeb030 (diff)
downloadgdb-b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a.zip
gdb-b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a.tar.gz
gdb-b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a.tar.bz2
Don't return stale data from fbsd_pid_to_exec_file for kernel processes.
For processes without an associated executable (such as kernel processes), the kern.proc.pathname.<pid> system control node returns a length of zero without modifying the user's buffer. Detect this case and return NULL rather than the previous contents of the static buffer 'buf'. gdb/ChangeLog: * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return NULL for an empty pathname.
Diffstat (limited to 'gdb/fbsd-nat.c')
-rw-r--r--gdb/fbsd-nat.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index ec4eed9..d0aaf89 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -63,7 +63,10 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid)
mib[3] = pid;
buflen = sizeof buf;
if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
- return buf;
+ /* The kern.proc.pathname.<pid> sysctl returns a length of zero
+ for processes without an associated executable such as kernel
+ processes. */
+ return buflen == 0 ? NULL : buf;
#endif
xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);