Skip to content

Commit

Permalink
Add ASan support (#6)
Browse files Browse the repository at this point in the history
* Add ASan support

* Add ASan support
  • Loading branch information
duffn authored Dec 19, 2024
1 parent c094ee7 commit 522faa1
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y \
build-essential \
libtool \
automake \
autoconf-archive \
python3-docutils

WORKDIR /
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ Fork, code, and PR! See build instructions above.

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

### Debugging

The module can also be built with [`AddressSanitizer`](https://github.com/google/sanitizers/wiki/AddressSanitizer) support.

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.

In order to build the module with this enabled, run the `bootstrap` script with `--enable-asan`.

```
./bootstrap --enable-asan
```

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.

_Note_: Do not use the module built with ASan support in production. This is meant for development purposes only.

## Acknowledgements

- The NY Times [`libvmod-queryfilter` VMOD](https://github.com/nytimes/libvmod-queryfilter/) for insipiration.
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ AC_ARG_WITH([rst2man],
[RST2MAN="$withval"],
[AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], [])])

AC_ARG_ENABLE([asan],
AS_HELP_STRING([--enable-asan],
[enable address sanitizer (default is NO)]),
[
ASAN_FLAGS="-fsanitize-recover=address"
AC_DEFINE([ENABLE_ASAN], [1],
[Define to 1 if ASAN sanitizer is enabled.])
], [])

if test -n "$ASAN_FLAGS"; then
AX_CHECK_COMPILE_FLAG([$ASAN_FLAGS -fsanitize-address-use-after-scope],
[ASAN_FLAGS="$ASAN_FLAGS -fsanitize-address-use-after-scope"],
[])
fi

CFLAGS="$CFLAGS $ASAN_FLAGS"
LDFLAGS="$LDFLAGS $ASAN_FLAGS"
VARNISH_PREREQ([7.0.0])
VARNISH_VMODS([querymodifier])

Expand Down
20 changes: 20 additions & 0 deletions debug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM varnish:7.6.1

USER root

RUN apt-get update && \
apt-get install --yes \
build-essential \
libtool \
automake \
python3-docutils \
autoconf-archive \
libasan8

WORKDIR /

COPY . /libvmod-querymodifier
RUN cd /libvmod-querymodifier \
&& ./bootstrap --enable-asan \
&& make \
&& make install
5 changes: 5 additions & 0 deletions debug/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server {
location / {
return 200 'OK';
}
}
14 changes: 14 additions & 0 deletions debug/default.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
vcl 4.1;

import querymodifier;
import std;

backend default {
.host = "nginx";
.port = "80";
}

sub vcl_recv {
std.syslog(180, "RECV: " + req.http.host + req.url);
set req.url = querymodifier.modifyparams(req.url, "ts,v,cacheFix,date", true);
}
19 changes: 19 additions & 0 deletions debug/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
varnish:
build:
context: ../
dockerfile: ./debug/Dockerfile
command: /entrypoint.sh
ports:
- 8080:80
environment:
- VARNISH_SIZE=200M
volumes:
- ./default.vcl:/etc/varnish/default.vcl
- ./entrypoint.sh:/entrypoint.sh
nginx:
image: nginx:1.27-alpine
ports:
- 8081:80
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
12 changes: 12 additions & 0 deletions debug/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libasan.so.8
export ASAN_OPTIONS=halt_on_error=0:detect_leaks=1

varnishd \
-F \
-f /etc/varnish/default.vcl \
-a http=:"${VARNISH_HTTP_PORT:-80}",HTTP \
-a proxy=:"${VARNISH_PROXY_PORT:-8443}",PROXY \
-p feature=+http2 \
-s malloc,"$VARNISH_SIZE"

0 comments on commit 522faa1

Please sign in to comment.