[PATCH v2 2/5] Don't return stale data from fbsd_pid_to_exec_file for kernel processes.
Simon Marchi
simark@simark.ca
Fri Jan 5 02:57:00 GMT 2018
On 2018-01-03 08:49 PM, John Baldwin wrote:
> 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 | 5 +++++
> gdb/fbsd-nat.c | 2 +-
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 29cfbb287b..804dd4f402 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2018-01-03 John Baldwin <jhb@FreeBSD.org>
> +
> + * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return
> + NULL for an empty pathname.
> +
> 2018-01-03 John Baldwin <jhb@FreeBSD.org>
>
> * fbsd-tdep.c (KVE_STRUCTSIZE, KVE_START, KVE_END, KVE_OFFSET)
> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> index ec4eed9abe..7b1d1bf148 100644
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -63,7 +63,7 @@ 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;
> + return buflen == 0 ? NULL : buf;
> #endif
>
> xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
>
LGTM, but maybe add a comment saying in what situation the sysctl can
return a buflen of 0.
Does the alternative method that reads from /proc/<pid>/exe work in that
case too?
Simon
More information about the Gdb-patches
mailing list