mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-13 17:00:19 +00:00
Merge pull request #3229 from cesanta/tests
fix possible overflow, improve tests
This commit is contained in:
6 files changed
+45
-16
No files matched your search
@@ -17,4 +17,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: make -C test ${{ matrix.target }}
|
- run: make -C test ${{ matrix.target }} ARGS="-max_total_time=7200"
|
||||||
|
|
||||||
|
# as we're not getting access to test units causing a problem, convert from the log:
|
||||||
|
# base64 -d > dataofdeath
|
||||||
|
# then paste the base64 data, enter, Ctrl-D; maybe check with hexdump -C dataofdeath
|
||||||
@@ -11462,6 +11462,7 @@ static int mg_tls_server_recv_hello(struct mg_connection *c) {
|
|||||||
uint16_t key_exchange_len;
|
uint16_t key_exchange_len;
|
||||||
uint8_t *key_exchange;
|
uint8_t *key_exchange;
|
||||||
uint16_t n = MG_LOAD_BE16(ext + j + 2);
|
uint16_t n = MG_LOAD_BE16(ext + j + 2);
|
||||||
|
if (((uint32_t) n + j + 4) > ext_len) goto fail;
|
||||||
if (MG_LOAD_BE16(ext + j) != 0x0033) { // not a key share extension, ignore
|
if (MG_LOAD_BE16(ext + j) != 0x0033) { // not a key share extension, ignore
|
||||||
j += (uint16_t) (n + 4);
|
j += (uint16_t) (n + 4);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -597,6 +597,7 @@ static int mg_tls_server_recv_hello(struct mg_connection *c) {
|
|||||||
uint16_t key_exchange_len;
|
uint16_t key_exchange_len;
|
||||||
uint8_t *key_exchange;
|
uint8_t *key_exchange;
|
||||||
uint16_t n = MG_LOAD_BE16(ext + j + 2);
|
uint16_t n = MG_LOAD_BE16(ext + j + 2);
|
||||||
|
if (((uint32_t) n + j + 4) > ext_len) goto fail;
|
||||||
if (MG_LOAD_BE16(ext + j) != 0x0033) { // not a key share extension, ignore
|
if (MG_LOAD_BE16(ext + j) != 0x0033) { // not a key share extension, ignore
|
||||||
j += (uint16_t) (n + 4);
|
j += (uint16_t) (n + 4);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+6
-2
@@ -117,7 +117,7 @@ unamalgamated: $(HDRS) Makefile packed_fs.c
|
|||||||
fuzz: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
fuzz: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
||||||
fuzz: mongoose.c mongoose.h Makefile fuzz.c
|
fuzz: mongoose.c mongoose.h Makefile fuzz.c
|
||||||
$(CC) fuzz.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer
|
$(CC) fuzz.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer
|
||||||
$(RUN) ./fuzzer
|
$(RUN) ./fuzzer $(ARGS)
|
||||||
|
|
||||||
FUZZDATA ?= /tmp/fuzzdata
|
FUZZDATA ?= /tmp/fuzzdata
|
||||||
fuzz2: mongoose.c mongoose.h Makefile fuzz.c
|
fuzz2: mongoose.c mongoose.h Makefile fuzz.c
|
||||||
@@ -127,7 +127,11 @@ fuzz2: mongoose.c mongoose.h Makefile fuzz.c
|
|||||||
fuzz_tls: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
fuzz_tls: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
||||||
fuzz_tls: mongoose.c mongoose.h Makefile fuzz_tls.c
|
fuzz_tls: mongoose.c mongoose.h Makefile fuzz_tls.c
|
||||||
$(CC) fuzz_tls.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer_tls
|
$(CC) fuzz_tls.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer_tls
|
||||||
$(RUN) ./fuzzer_tls -max_len=17000
|
$(RUN) ./fuzzer_tls -max_len=17000 $(ARGS)
|
||||||
|
|
||||||
|
fuzz_tls2: mongoose.c mongoose.h Makefile fuzz_tls.c
|
||||||
|
$(CC) fuzz_tls.c -DMAIN $(OPTS) $(WARN) $(ASAN) $(INCS) -o fuzzer_tls
|
||||||
|
$(RUN) ./fuzzer_tls $(FUZZDATA)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// https://llvm.org/docs/LibFuzzer.html
|
||||||
|
|
||||||
#define MG_ENABLE_SOCKET 0
|
#define MG_ENABLE_SOCKET 0
|
||||||
#define MG_ENABLE_LOG 0
|
#define MG_ENABLE_LOG 0
|
||||||
#define MG_ENABLE_LINES 1
|
#define MG_ENABLE_LINES 1
|
||||||
|
|||||||
+30
-13
@@ -1,3 +1,5 @@
|
|||||||
|
// https://llvm.org/docs/LibFuzzer.html
|
||||||
|
|
||||||
#define MG_ENABLE_SOCKET 1
|
#define MG_ENABLE_SOCKET 1
|
||||||
#define MG_ENABLE_LOG 0
|
#define MG_ENABLE_LOG 0
|
||||||
#define MG_ENABLE_LINES 1
|
#define MG_ENABLE_LINES 1
|
||||||
@@ -12,28 +14,40 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
|
|||||||
#else
|
#else
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
|
int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
|
||||||
#endif
|
#endif
|
||||||
typedef int (*f)(struct mg_connection *);
|
|
||||||
|
|
||||||
f f_[] = {
|
// Preprocessor magic, just add/remove functions here and leave the rest alone
|
||||||
mg_tls_server_recv_hello,
|
#define TABLE(_) \
|
||||||
#if 0
|
_(mg_tls_server_recv_hello) \
|
||||||
mg_tls_client_recv_hello,
|
//_(mg_tls_client_recv_hello) \
|
||||||
mg_tls_client_recv_ext,
|
//_(mg_tls_client_recv_ext ) \
|
||||||
mg_tls_client_recv_cert,
|
//_(mg_tls_client_recv_cert) \
|
||||||
mg_tls_client_recv_cert_verify
|
//_(mg_tls_client_recv_cert_verify) \
|
||||||
#endif
|
// ...
|
||||||
|
|
||||||
|
struct f {
|
||||||
|
int (*f)(struct mg_connection *);
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct f f_[] = {
|
||||||
|
#define ENTRY(func) { func, #func },
|
||||||
|
TABLE(ENTRY)
|
||||||
|
#undef ENTRY
|
||||||
|
};
|
||||||
|
// end of preprocessor magic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
struct mg_connection c_[sizeof(f_)/sizeof(f)], *c = &c_[0];
|
struct mg_connection c_[sizeof(f_)/sizeof(struct f)], *c = &c_[0];
|
||||||
struct tls_data tls_[sizeof(f_)/sizeof(f)];
|
struct tls_data tls_[sizeof(f_)/sizeof(struct f)];
|
||||||
int i;
|
int i;
|
||||||
if (size == 0) return 0;
|
if (size == 0) return 0;
|
||||||
mg_log_set(MG_LL_INFO);
|
mg_log_set(MG_LL_INFO);
|
||||||
memset(c, 0, sizeof(*c));
|
memset(c, 0, sizeof(*c));
|
||||||
c->send.align = c->recv.align = c->rtls.align = MG_IO_SIZE;
|
c->send.align = c->recv.align = c->rtls.align = MG_IO_SIZE;
|
||||||
c->is_tls = c->is_tls_hs = 1;
|
c->is_tls = c->is_tls_hs = 1;
|
||||||
for (i = 0; i < (int)(sizeof(f_)/sizeof(f)); i++) {
|
for (i = 0; i < (int)(sizeof(f_)/sizeof(struct f)); i++) {
|
||||||
struct mg_iobuf *io;
|
struct mg_iobuf *io;
|
||||||
c = &c_[i];
|
c = &c_[i];
|
||||||
io = &c->rtls;
|
io = &c->rtls;
|
||||||
@@ -47,7 +61,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|||||||
memcpy(&io->buf[io->len], data, size);
|
memcpy(&io->buf[io->len], data, size);
|
||||||
io->len += size;
|
io->len += size;
|
||||||
c->tls = &tls_[i];
|
c->tls = &tls_[i];
|
||||||
f_[i](&c[i]);
|
#ifdef PRINT_FUNCNAME
|
||||||
|
printf("CALLING %s\n", f_[i].name);
|
||||||
|
#endif
|
||||||
|
f_[i].f(&c[i]);
|
||||||
mg_iobuf_free(io);
|
mg_iobuf_free(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user