summaryrefslogtreecommitdiff
path: root/gdb/darwin-nat.c
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2017-02-14 18:27:23 -0500
committerSergio Durigan Junior <sergiodj@redhat.com>2017-02-20 07:48:44 -0500
commit0db8980cc0ee05727c11f8b7c6674137a4d5de4e (patch)
treebfbdd67b9e700284dfe4a94e47cbcd1af790d6d5 /gdb/darwin-nat.c
parent246b91226bbc60bf3b2a4e1a65edc0c577e487c0 (diff)
PR gdb/16188: Verify PTRACE_TRACEME succeeded
This patch fixes PR gdb/16188, which is about the fact that fork_inferior doesn't verify the return value of the "traceme_fun" callback. On most targets, this callback is actually a wrapper to a ptrace call that does a PTRACE_TRACEME on the forked GDB process that will eventually become the inferior. Thanks to Pedro, this second version of the patch is simpler and more more logical. Basically, two helper functions are added: trace_start_error and trace_start_error_with_name. The former can be used when there is a customized error message to be printed to the user. The latter works like perror_with_name, so you just need to pass the function that error'd. Both helper functions mentioned above do basically the same thing: print the error message to stderr and call _exit, properly terminating the forked inferior. Most of the patch takes care of guarding the necessary system calls against errors on the "traceme_fun" callbacks. It is not right to call error on these situations, so I've replaced these calls with the proper helper function call. Regression-tested on BuildBot. Thanks, gdb/ChangeLog: 2017-02-20 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> PR gdb/16188 * darwin-nat.c (darwin_ptrace_me): Check if calls to system calls succeeded. * fork-child.c (trace_start_error): New function. (trace_start_error_with_name): Likewise. * gnu-nat.c (gnu_ptrace_me): Check if call to PTRACE succeeded. * inf-ptrace.c (inf_ptrace_me): Likewise. * inferior.h (trace_start_error): New prototype. (trace_start_error_with_name): Likewise.
Diffstat (limited to 'gdb/darwin-nat.c')
-rw-r--r--gdb/darwin-nat.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 8c5e8a0b1f..edee1be858 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1729,22 +1729,28 @@ darwin_ptrace_me (void)
char c;
/* Close write end point. */
- close (ptrace_fds[1]);
+ if (close (ptrace_fds[1]) < 0)
+ trace_start_error_with_name ("close");
/* Wait until gdb is ready. */
res = read (ptrace_fds[0], &c, 1);
if (res != 0)
- error (_("unable to read from pipe, read returned: %d"), res);
- close (ptrace_fds[0]);
+ trace_start_error (_("unable to read from pipe, read returned: %d"), res);
+
+ if (close (ptrace_fds[0]) < 0)
+ trace_start_error_with_name ("close");
/* Get rid of privileges. */
- setegid (getgid ());
+ if (setegid (getgid ()) < 0)
+ trace_start_error_with_name ("setegid");
/* Set TRACEME. */
- PTRACE (PT_TRACE_ME, 0, 0, 0);
+ if (PTRACE (PT_TRACE_ME, 0, 0, 0) < 0)
+ trace_start_error_with_name ("PTRACE");
/* Redirect signals to exception port. */
- PTRACE (PT_SIGEXC, 0, 0, 0);
+ if (PTRACE (PT_SIGEXC, 0, 0, 0) < 0)
+ trace_start_error_with_name ("PTRACE");
}
/* Dummy function to be sure fork_inferior uses fork(2) and not vfork(2). */