From: Emmanuel Dreyfus Date: Wed, 19 Dec 2018 10:11:16 +0000 (+0100) Subject: Fix startup crash when running outside of gdb on BSD systems X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6212140fe9ef96fbd61bb7d4622b752cfaf5ee20;p=thirdparty%2Ffreeradius-server.git Fix startup crash when running outside of gdb on BSD systems On BSD systems, ptrace(PT_DETACH) uses a third argument for resume address, with the magic value (void *)1 to resume where process stopped. Specifying NULL there leads to a crash because process resumes at address 0. We introduce an OS-dependent _PTRACE_DETACH macro to specify third argument as NULL on Linux and (void *)1 on other systems. Always using (void *)1 could be another solution, since basic tests suggests passing (void *)1 as third argument on Linux does not cause harm. --- diff --git a/src/lib/util/debug.c b/src/lib/util/debug.c index 6f1195ce309..a07f4217e5c 100644 --- a/src/lib/util/debug.c +++ b/src/lib/util/debug.c @@ -112,11 +112,19 @@ static struct rlimit init_core_limit; static TALLOC_CTX *talloc_autofree_ctx; +/* + * On BSD systems, ptrace(PT_DETACH) uses a third argument for + * resume address, with the magic value (void *)1 to resume where + * process stopped. Specifying NULL there leads to a crash because + * process resumes at address 0. + */ #ifdef HAVE_SYS_PTRACE_H # ifdef __linux__ # define _PTRACE(_x, _y) ptrace(_x, _y, NULL, NULL) +# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, NULL, NULL) # else # define _PTRACE(_x, _y) ptrace(_x, _y, NULL, 0) +# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, (void *)1, NULL) # endif # ifdef HAVE_CAPABILITY_H @@ -340,7 +348,7 @@ DIAG_ON(deprecated-declarations); } /* Detach */ - _PTRACE(PT_DETACH, ppid); + _PTRACE_DETACH(ppid); exit(0); }