Skip to content

Commit ac3951d

Browse files
committed
tests: Allow running tests under ASAN+UBSAN
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.
1 parent e192e3f commit ac3951d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

libqrexec/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
CC=gcc
1+
CC ?=gcc
22
VCHAN_PKG = $(if $(BACKEND_VMM),vchan-$(BACKEND_VMM),vchan)
33
override QUBES_CFLAGS := -I. -I../libqrexec -g -O2 -Wall -Wextra -Werror \
44
$(shell pkg-config --cflags $(VCHAN_PKG)) -fstack-protector \
55
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIC -std=gnu11 -D_POSIX_C_SOURCE=200809L \
66
-D_GNU_SOURCE $(CFLAGS) \
7-
-Wstrict-prototypes -Wold-style-definition -Wmissing-declarations
7+
-Wstrict-prototypes -Wold-style-definition -Wmissing-declarations \
8+
-fno-delete-null-pointer-checks
89

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

libqrexec/buffer.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <string.h>
26+
#include <assert.h>
2627
#include "libqrexec-utils.h"
2728

2829
#define BUFFER_LIMIT 50000000
@@ -79,6 +80,7 @@ void buffer_append(struct buffer *b, const char *data, int len)
7980
{
8081
int newsize;
8182
char *qdata;
83+
assert(data != NULL && "NULL data");
8284
if (b->buflen < 0 || b->buflen > BUFFER_LIMIT) {
8385
LOG(ERROR, "buffer_append buflen %d", len);
8486
exit(1);
@@ -91,7 +93,9 @@ void buffer_append(struct buffer *b, const char *data, int len)
9193
return;
9294
newsize = len + b->buflen;
9395
qdata = limited_malloc(len + b->buflen);
94-
memcpy(qdata, b->data, (size_t)b->buflen);
96+
if (b->data != 0) {
97+
memcpy(qdata, b->data, (size_t)b->buflen);
98+
}
9599
memcpy(qdata + b->buflen, data, (size_t)len);
96100
buffer_free(b);
97101
b->buflen = newsize;

run-tests

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ if command -v dnf >/dev/null; then
55
sudo dnf install python3dist\({coverage,pytest,gbulb,pyinotify,pytest-asyncio}\) || :
66
fi
77
if pkg-config vchan-socket; then
8-
export CFLAGS="--coverage -DCOVERAGE"
9-
export LDFLAGS=--coverage
8+
if [[ -n "${USE_ASAN-}" ]]; then
9+
export CFLAGS=-fsanitize=address,undefined
10+
export LDFLAGS=-fsanitize=address,undefined
11+
# MUST use clang here. GCC causes random SIGSEGV crashes
12+
# when ASAN and UBSAN is in use. Release build (no sanitizers)
13+
# works fine.
14+
export CC=clang
15+
export ASAN_OPTIONS=leak_check_at_exit=0
16+
else
17+
export CFLAGS="--coverage -DCOVERAGE"
18+
export LDFLAGS=--coverage
19+
fi
1020
make -C libqrexec BACKEND_VMM=socket clean all
1121
make -C agent BACKEND_VMM=socket clean all
1222
make -C daemon BACKEND_VMM=socket clean all

0 commit comments

Comments
 (0)