Ticket #13471: tor-0.2.4.24-as.patch

File tor-0.2.4.24-as.patch, 2.7 KB (added by starlight, 5 years ago)

patch for tor, apply after running configure

  • Makefile

    old new  
    419419BUILDDIR = /w/gpl/tor-0.2.4.24-as
    420420CC = gcc
    421421CCDEPMODE = depmode=gcc3
    422 CFLAGS = -g -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wstack-protector -fwrapv --param ssp-buffer-size=1 -fPIE -Wall -fno-strict-aliasing
     422CFLAGS = -g -O1 -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wstack-protector -fwrapv --param ssp-buffer-size=1 -fPIE -Wall -fno-strict-aliasing -fsanitize=address -fno-inline-functions-called-once -fno-omit-frame-pointer
    423423CONFDIR = /usr/local/etc/tor
    424424CPP = gcc -E
    425425CPPFLAGS = -I/w/gpl/gcc-4.9.1/libsanitizer/include -I/usr/local/include -I${top_srcdir}/src/common   
  • src/common/util.c

    old new  
    7272#ifdef HAVE_SYS_FCNTL_H
    7373#include <sys/fcntl.h>
    7474#endif
     75#ifdef HAVE_PRCTL
     76#include <sys/prctl.h>
     77#endif
    7578#ifdef HAVE_TIME_H
    7679#include <time.h>
    7780#endif
     
    9396#include <sys/wait.h>
    9497#endif
    9598
     99#include <stdbool.h>
     100#include <sanitizer/asan_interface.h>
     101
    96102/* =====
    97103 * Memory management
    98104 * ===== */
     
    31353141finish_daemon(const char *desired_cwd)
    31363142{
    31373143  int nullfd;
     3144  int outfd;
     3145  int errfd;
    31383146  char c = '.';
    31393147  if (finish_daemon_called)
    31403148    return;
     
    31503158    exit(1);
    31513159  }
    31523160
    3153   nullfd = tor_open_cloexec("/dev/null", O_RDWR, 0);
    3154   if (nullfd < 0) {
     3161  nullfd = tor_open_cloexec("/dev/null", O_RDONLY, 0);
     3162  if (nullfd < 3) {
    31553163    log_err(LD_GENERAL,"/dev/null can't be opened. Exiting.");
    31563164    exit(1);
    31573165  }
     3166  outfd = tor_open_cloexec("out.tor", O_WRONLY | O_CREAT | O_APPEND, 0);
     3167  if (outfd < 3) {
     3168    log_err(LD_GENERAL,"out.tor can't be opened. Exiting.");
     3169    exit(1);
     3170  }
     3171  errfd = tor_open_cloexec("err.tor", O_WRONLY | O_CREAT | O_APPEND, 0);
     3172  if (errfd < 3) {
     3173    log_err(LD_GENERAL,"err.tor can't be opened. Exiting.");
     3174    exit(1);
     3175  }
    31583176  /* close fds linking to invoking terminal, but
    31593177   * close usual incoming fds, but redirect them somewhere
    31603178   * useful so the fds don't get reallocated elsewhere.
    31613179   */
    31623180  if (dup2(nullfd,0) < 0 ||
    3163       dup2(nullfd,1) < 0 ||
    3164       dup2(nullfd,2) < 0) {
     3181      dup2(outfd,1) < 0 ||
     3182      dup2(errfd,2) < 0) {
    31653183    log_err(LD_GENERAL,"dup2 failed. Exiting.");
    31663184    exit(1);
    31673185  }
    3168   if (nullfd > 2)
    3169     close(nullfd);
     3186  close(errfd);
     3187  close(outfd);
     3188  close(nullfd);
     3189#ifdef HAVE_PRCTL
     3190  if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) != 0) {
     3191    log_err(LD_GENERAL,"prctl failed. Exiting.");
     3192    exit(1);
     3193  }
     3194#endif
     3195  __sanitizer_sandbox_on_notify(NULL);
    31703196  /* signal success */
    31713197  if (write(daemon_filedes[1], &c, sizeof(char)) != sizeof(char)) {
    31723198    log_err(LD_GENERAL,"write failed. Exiting.");