Home | History | Annotate | Download | only in apache-httpd
      1 diff -Nur httpd/compile_and_install.sh httpd.new/compile_and_install.sh
      2 --- httpd/compile_and_install.sh	1970-01-01 01:00:00.000000000 +0100
      3 +++ httpd.new/compile_and_install.sh	2017-11-02 23:48:05.049844778 +0100
      4 @@ -0,0 +1,62 @@
      5 +#!/bin/sh
      6 +
      7 +set -ex
      8 +
      9 +# Directory with honggfuzz installation
     10 +HFUZZ_DIR="/home/jagger/src/honggfuzz"
     11 +# Change this to a directory where apache should be installed into
     12 +INSTALL_PREFIX="$(realpath "$PWD/../dist")"
     13 +NGHTTP2_VER=1.29.0
     14 +APR_VER=1.6.3
     15 +APR_UTIL_VER=1.6.1
     16 +CFLAGS_SAN="-fsanitize=address"
     17 +# Another viable option: few
     18 +APACHE_MODULES=most
     19 +
     20 +NGHTTP2_PATH="$(realpath "$PWD/../nghttp2-$NGHTTP2_VER")/"
     21 +APR_PATH="$(realpath "$PWD/../apr-$APR_VER")"
     22 +APR_UTIL_PATH="$(realpath "$PWD/../apr-util-$APR_UTIL_VER")/"
     23 +
     24 +export CC="$HFUZZ_DIR/hfuzz_cc/hfuzz-clang"
     25 +export CXX="$HFUZZ_DIR/hfuzz_cc/hfuzz-clang++"
     26 +
     27 +echo "Compiling APR"
     28 +cd "$APR_PATH"
     29 +CFLAGS="$CFLAGS_SAN" ./configure --disable-shared --enable-static
     30 +make clean
     31 +make -j$(nproc)
     32 +cd -
     33 +
     34 +echo "Compiling APR-UTIL"
     35 +cd "$APR_UTIL_PATH"
     36 +CFLAGS="$CFLAGS_SAN" ./configure --with-apr="$APR_PATH" --disable-shared --enable-static
     37 +make clean
     38 +make -j$(nproc)
     39 +cd -
     40 +
     41 +echo "Compiling NGHTTP2"
     42 +cd "$NGHTTP2_PATH"
     43 +CFLAGS="$CFLAGS_SAN" CXXFLAGS="$CFLAGS_SAN" ./configure --disable-shared --enable-static
     44 +make clean
     45 +make -j$(nproc)
     46 +cd -
     47 +
     48 +echo "Install PATH: $INSTALL_PREFIX"
     49 +./buildconf --with-apr="$APR_PATH" --with-apr-util="$APR_UTIL_PATH"
     50 +
     51 +echo "Compiling HTTPD"
     52 +CC="$HFUZZ_DIR/hfuzz_cc/hfuzz-clang" CXX="$HFUZZ_DIR/hfuzz_cc/hfuzz-clang++" CFLAGS="-I$NGHTTP2_PATH/lib/includes $CFLAGS_SAN -ggdb -O3" LDFLAGS="-L$NGHTTP2_PATH/lib -lpthread" \
     53 +./configure \
     54 +		--prefix="$INSTALL_PREFIX" \
     55 +		--with-nghttp2="$NGHTTP2_PATH/" \
     56 +		--enable-http2 \
     57 +		--enable-nghttp2-staticlib-deps \
     58 +		--with-mpm=event \
     59 +		--enable-unixd \
     60 +		--disable-pie \
     61 +		--enable-mods-static=$APACHE_MODULES \
     62 +		--with-apr="$APR_PATH" \
     63 +		--with-apr-util="$APR_UTIL_PATH"
     64 +make clean
     65 +make -j$(nproc)
     66 +make install
     67 diff -Nur httpd/configure.in httpd.new/configure.in
     68 --- httpd/configure.in	2017-11-02 23:48:27.717470876 +0100
     69 +++ httpd.new/configure.in	2017-11-02 23:48:05.053844712 +0100
     70 @@ -721,7 +721,7 @@
     71  if test "x$PKGCONFIG" != "x" && `$PKGCONFIG --atleast-version='0.9.12' check`; then
     72    UNITTEST_CFLAGS=`$PKGCONFIG --cflags check`
     73    UNITTEST_LIBS=`$PKGCONFIG --libs check`
     74 -  other_targets="$other_targets test/httpdunit"
     75 +  other_targets="$other_targets"
     76  
     77    AC_MSG_RESULT([yes])
     78  else
     79 diff -Nur httpd/server/main.c httpd.new/server/main.c
     80 --- httpd/server/main.c	2017-11-02 23:48:27.913467639 +0100
     81 +++ httpd.new/server/main.c	2017-11-02 23:48:05.053844712 +0100
     82 @@ -484,8 +484,84 @@
     83      destroy_and_exit_process(process, 1);
     84  }
     85  
     86 -int main(int argc, const char * const argv[])
     87 -{
     88 +#include <libhfuzz/libhfuzz.h>
     89 +
     90 +static void GETDATA(void *unused) {
     91 +  usleep(100000);
     92 +
     93 +  for (;;) {
     94 +    size_t len;
     95 +    const uint8_t *buf;
     96 +
     97 +    HF_ITER(&buf, &len);
     98 +
     99 +    int myfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
    100 +    if (myfd == -1) {
    101 +      perror("socket");
    102 +      _exit(1);
    103 +    }
    104 +
    105 +    int sz = (1024 * 1024);
    106 +    if (setsockopt(myfd, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)) == -1) {
    107 +      perror("setsockopt");
    108 +      exit(1);
    109 +    }
    110 +
    111 +    struct sockaddr_in saddr;
    112 +    saddr.sin_family = AF_INET;
    113 +    saddr.sin_port = htons(8080);
    114 +    saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    115 +    if (connect(myfd, &saddr, sizeof(saddr)) == -1) {
    116 +      perror("connect");
    117 +      close(myfd);
    118 +      continue;
    119 +    }
    120 +
    121 +    if (send(myfd, buf, len, MSG_NOSIGNAL) != len) {
    122 +      perror("send() failed 1");
    123 +      exit(1);
    124 +    }
    125 +
    126 +    if (shutdown(myfd, SHUT_WR) == -1) {
    127 +      perror("shutdown");
    128 +      exit(1);
    129 +    }
    130 +
    131 +    char b[1024 * 1024];
    132 +    while (recv(myfd, b, sizeof(b), MSG_WAITALL) > 0) {} ;
    133 +
    134 +    close(myfd);
    135 +  }
    136 +}
    137 +
    138 +static void LAUNCHTHR() {
    139 +  if (linuxEnterNs(CLONE_NEWUSER|CLONE_NEWNET|CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS) == false) {
    140 +    exit(1);
    141 +  }
    142 +  if (linuxIfaceUp("lo") == false) {
    143 +    exit(1);
    144 +  }
    145 +  if (linuxMountTmpfs("/tmp") == false) {
    146 +    exit(1);
    147 +  }
    148 +
    149 +  pthread_t t;
    150 +  pthread_attr_t attr;
    151 +
    152 +  pthread_attr_init(&attr);
    153 +  pthread_attr_setstacksize(&attr, 1024 * 1024 * 8);
    154 +  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    155 +
    156 +  pthread_create(&t, &attr, GETDATA,  NULL);
    157 +}
    158 +
    159 + int main(int argc, const char * const argv[])
    160 + {
    161 +
    162 +  if (getenv("NO_FUZZ") == NULL) {
    163 +        LAUNCHTHR();
    164 +  }
    165 +
    166      char c;
    167      int showcompile = 0, showdirectives = 0;
    168      const char *confname = SERVER_CONFIG_FILE;
    169