Skip to content

Commit 522faa1

Browse files
authored
Add ASan support (#6)
* Add ASan support * Add ASan support
1 parent c094ee7 commit 522faa1

8 files changed

+104
-0
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y \
77
build-essential \
88
libtool \
99
automake \
10+
autoconf-archive \
1011
python3-docutils
1112

1213
WORKDIR /

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ Fork, code, and PR! See build instructions above.
7676

7777
I'm happy to review any PRs. Any bug reports are also welcome.
7878

79+
### Debugging
80+
81+
The module can also be built with [`AddressSanitizer`](https://github.com/google/sanitizers/wiki/AddressSanitizer) support.
82+
83+
It is recommended that when developing on the module, you build with `AddressSanitizer` support enabled in order to help identify any memory issues with the VMOD.
84+
85+
In order to build the module with this enabled, run the `bootstrap` script with `--enable-asan`.
86+
87+
```
88+
./bootstrap --enable-asan
89+
```
90+
91+
There are also some scripts in the `debug` directory to assist. Navigate to the `debug` directory and run `docker compose up --build` in order to build the module with ASan support as well as with a backend `nginx` to field example requests.
92+
93+
_Note_: Do not use the module built with ASan support in production. This is meant for development purposes only.
94+
7995
## Acknowledgements
8096

8197
- The NY Times [`libvmod-queryfilter` VMOD](https://github.com/nytimes/libvmod-queryfilter/) for insipiration.

configure.ac

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ AC_ARG_WITH([rst2man],
1818
[RST2MAN="$withval"],
1919
[AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], [])])
2020

21+
AC_ARG_ENABLE([asan],
22+
AS_HELP_STRING([--enable-asan],
23+
[enable address sanitizer (default is NO)]),
24+
[
25+
ASAN_FLAGS="-fsanitize-recover=address"
26+
AC_DEFINE([ENABLE_ASAN], [1],
27+
[Define to 1 if ASAN sanitizer is enabled.])
28+
], [])
29+
30+
if test -n "$ASAN_FLAGS"; then
31+
AX_CHECK_COMPILE_FLAG([$ASAN_FLAGS -fsanitize-address-use-after-scope],
32+
[ASAN_FLAGS="$ASAN_FLAGS -fsanitize-address-use-after-scope"],
33+
[])
34+
fi
35+
36+
CFLAGS="$CFLAGS $ASAN_FLAGS"
37+
LDFLAGS="$LDFLAGS $ASAN_FLAGS"
2138
VARNISH_PREREQ([7.0.0])
2239
VARNISH_VMODS([querymodifier])
2340

debug/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM varnish:7.6.1
2+
3+
USER root
4+
5+
RUN apt-get update && \
6+
apt-get install --yes \
7+
build-essential \
8+
libtool \
9+
automake \
10+
python3-docutils \
11+
autoconf-archive \
12+
libasan8
13+
14+
WORKDIR /
15+
16+
COPY . /libvmod-querymodifier
17+
RUN cd /libvmod-querymodifier \
18+
&& ./bootstrap --enable-asan \
19+
&& make \
20+
&& make install

debug/default.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
server {
2+
location / {
3+
return 200 'OK';
4+
}
5+
}

debug/default.vcl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vcl 4.1;
2+
3+
import querymodifier;
4+
import std;
5+
6+
backend default {
7+
.host = "nginx";
8+
.port = "80";
9+
}
10+
11+
sub vcl_recv {
12+
std.syslog(180, "RECV: " + req.http.host + req.url);
13+
set req.url = querymodifier.modifyparams(req.url, "ts,v,cacheFix,date", true);
14+
}

debug/docker-compose.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
varnish:
3+
build:
4+
context: ../
5+
dockerfile: ./debug/Dockerfile
6+
command: /entrypoint.sh
7+
ports:
8+
- 8080:80
9+
environment:
10+
- VARNISH_SIZE=200M
11+
volumes:
12+
- ./default.vcl:/etc/varnish/default.vcl
13+
- ./entrypoint.sh:/entrypoint.sh
14+
nginx:
15+
image: nginx:1.27-alpine
16+
ports:
17+
- 8081:80
18+
volumes:
19+
- ./default.conf:/etc/nginx/conf.d/default.conf

debug/entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libasan.so.8
4+
export ASAN_OPTIONS=halt_on_error=0:detect_leaks=1
5+
6+
varnishd \
7+
-F \
8+
-f /etc/varnish/default.vcl \
9+
-a http=:"${VARNISH_HTTP_PORT:-80}",HTTP \
10+
-a proxy=:"${VARNISH_PROXY_PORT:-8443}",PROXY \
11+
-p feature=+http2 \
12+
-s malloc,"$VARNISH_SIZE"

0 commit comments

Comments
 (0)