Skip to content

Commit

Permalink
tests: Allow running tests under ASAN+UBSAN
Browse files Browse the repository at this point in the history
memcpy() must not be called on a NULL pointer, even if the size is 0.
Furthermore, leak checks must be disabled to avoid wrong exit codes.
Finally, use clang if turning on sanitizers.  Otherwise, Fedora 39's
gcc-13.2.1-7.fc39.x86_64 package produces binaries that crash with
SIGSEGV.
  • Loading branch information
DemiMarie committed Apr 1, 2024
1 parent e192e3f commit ac3951d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions libqrexec/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CC=gcc
CC ?=gcc
VCHAN_PKG = $(if $(BACKEND_VMM),vchan-$(BACKEND_VMM),vchan)
override QUBES_CFLAGS := -I. -I../libqrexec -g -O2 -Wall -Wextra -Werror \
$(shell pkg-config --cflags $(VCHAN_PKG)) -fstack-protector \
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIC -std=gnu11 -D_POSIX_C_SOURCE=200809L \
-D_GNU_SOURCE $(CFLAGS) \
-Wstrict-prototypes -Wold-style-definition -Wmissing-declarations
-Wstrict-prototypes -Wold-style-definition -Wmissing-declarations \
-fno-delete-null-pointer-checks

override LDFLAGS += -pie -Wl,-z,relro,-z,now -shared

Expand Down
6 changes: 5 additions & 1 deletion libqrexec/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libqrexec-utils.h"

#define BUFFER_LIMIT 50000000
Expand Down Expand Up @@ -79,6 +80,7 @@ void buffer_append(struct buffer *b, const char *data, int len)
{
int newsize;
char *qdata;
assert(data != NULL && "NULL data");
if (b->buflen < 0 || b->buflen > BUFFER_LIMIT) {
LOG(ERROR, "buffer_append buflen %d", len);
exit(1);
Expand All @@ -91,7 +93,9 @@ void buffer_append(struct buffer *b, const char *data, int len)
return;
newsize = len + b->buflen;
qdata = limited_malloc(len + b->buflen);
memcpy(qdata, b->data, (size_t)b->buflen);
if (b->data != 0) {
memcpy(qdata, b->data, (size_t)b->buflen);
}
memcpy(qdata + b->buflen, data, (size_t)len);
buffer_free(b);
b->buflen = newsize;
Expand Down
14 changes: 12 additions & 2 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ if command -v dnf >/dev/null; then
sudo dnf install python3dist\({coverage,pytest,gbulb,pyinotify,pytest-asyncio}\) || :
fi
if pkg-config vchan-socket; then
export CFLAGS="--coverage -DCOVERAGE"
export LDFLAGS=--coverage
if [[ -n "${USE_ASAN-}" ]]; then
export CFLAGS=-fsanitize=address,undefined
export LDFLAGS=-fsanitize=address,undefined
# MUST use clang here. GCC causes random SIGSEGV crashes
# when ASAN and UBSAN is in use. Release build (no sanitizers)
# works fine.
export CC=clang
export ASAN_OPTIONS=leak_check_at_exit=0
else
export CFLAGS="--coverage -DCOVERAGE"
export LDFLAGS=--coverage
fi
make -C libqrexec BACKEND_VMM=socket clean all
make -C agent BACKEND_VMM=socket clean all
make -C daemon BACKEND_VMM=socket clean all
Expand Down

0 comments on commit ac3951d

Please sign in to comment.