Skip to content

Commit

Permalink
Merge pull request comotion#33 from ssm/patches/support_freebsd
Browse files Browse the repository at this point in the history
Fixes comotion#32, as bsd doesnt support prctl
  • Loading branch information
comotion committed Oct 17, 2012
2 parents b7b1deb + c58b300 commit 2ba8958
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ AC_SUBST(LIBGPGME_CFLAGS)
AC_MSG_NOTICE([checking header files])
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h getopt.h libintl.h locale.h stdlib.h sys/fsuid.h sys/ioctl.h termios.h])
AC_CHECK_HEADERS(sys/prctl.h)

# Checks for typedefs, structures, and compiler characteristics.
AC_MSG_NOTICE([checking typedefs, structures, and compiler characteristics])
Expand Down
8 changes: 6 additions & 2 deletions security.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
*/
#include <sys/utsname.h>
#include "cpm.h"
#if defined(HAVE_SYS_PRCTL_H)
#include <sys/ptrace.h>
#include <sys/prctl.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <regex.h>
Expand Down Expand Up @@ -510,20 +512,22 @@ int initSecurity(int* max_mem_lock, int* memory_safe, int* ptrace_safe,
}

if (p == 0) {
#if defined(HAVE_SYS_PRCTL_H)
// makes the child unattachable
if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) != 0) {
fprintf(stderr, "Can not set child non dumpable\n");
_exit(1);
}
#endif

if (ptrace(PTRACE_ATTACH, p0, 0, 0) != 0) {
if (ptrace(PT_ATTACH, p0, 0, 0) != 0) {
// someone is already attached to us; shoot the parent in the head
fprintf(stderr, "Can't attach to parent!\n");
kill(p0, SIGKILL);
_exit(1);
}
while (1) {
if(ptrace(PTRACE_SYSCALL, p0, 0, 0) == 0)
if(ptrace(PT_SYSCALL, p0, 0, 0) == 0)
waitpid(p0, &status, 0);
if(errno == ESRCH && kill(p0, 0) == -1)
exit(0); // parent is dead
Expand Down

0 comments on commit 2ba8958

Please sign in to comment.