This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Don't return stale data from fbsd_pid_to_exec_file for kernel processes.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a

commit b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a
Author: John Baldwin <jhb@FreeBSD.org>
Date:   Tue Jan 9 13:35:17 2018 -0800

    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.

Diff:
---
 gdb/ChangeLog  | 5 +++++
 gdb/fbsd-nat.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e7f3cc2..3752a3b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2018-01-09  John Baldwin  <jhb@FreeBSD.org>
 
+	* fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return
+	NULL for an empty pathname.
+
+2018-01-09  John Baldwin  <jhb@FreeBSD.org>
+
 	* fbsd-tdep.c (KVE_STRUCTSIZE, KVE_START, KVE_END, KVE_OFFSET)
 	(KVE_FLAGS, KVE_PROTECTION, KVE_PATH, KINFO_VME_PROT_READ)
 	(KINFO_VME_PROT_WRITE, KINFO_VME_PROT_EXEC, KINFO_VME_FLAG_COW)
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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]