]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't return stale data from fbsd_pid_to_exec_file for kernel processes.
authorJohn Baldwin <jhb@FreeBSD.org>
Tue, 9 Jan 2018 21:35:17 +0000 (13:35 -0800)
committerJohn Baldwin <jhb@FreeBSD.org>
Tue, 9 Jan 2018 21:35:17 +0000 (13:35 -0800)
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.

gdb/ChangeLog
gdb/fbsd-nat.c

index e7f3cc2052630575706797c1be13d195a9684cc7..3752a3b1a19796d49eaa7e1f31701f0676983a4c 100644 (file)
@@ -1,3 +1,8 @@
+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)
index ec4eed9abe309548e3f602e0b873157d0a03b557..d0aaf8914568be09515633c81e89a57a86f262d2 100644 (file)
@@ -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);