mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 02:59:01 +08:00
Add dns test case
This commit is contained in:
parent
7ce9cdf0b9
commit
348c579521
2
Makefile
2
Makefile
@ -45,7 +45,7 @@ unamalgamated: $(SRCS) $(HDRS) Makefile
|
||||
$(CLANG) src/*.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
|
||||
|
||||
fuzz: mongoose.c mongoose.h Makefile test/fuzz.c
|
||||
$(CLANG)++ mongoose.c test/fuzz.c $(CFLAGS) -DMG_ENABLE_LINES -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address $(LDFLAGS) -g -o fuzzer
|
||||
$(CLANG) mongoose.c test/fuzz.c $(CFLAGS) -DMG_ENABLE_LINES -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address $(LDFLAGS) -g -o fuzzer
|
||||
$(DEBUGGER) ./fuzzer
|
||||
|
||||
# make CLANG=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
|
||||
|
@ -945,9 +945,24 @@ static void test_str(void) {
|
||||
|
||||
static void test_dns(void) {
|
||||
struct mg_dns_message dm;
|
||||
// txid flags numQ numA numAP numOP
|
||||
// 0000 00 01 81 80 00 01 00 01 00 00 00 00 07 63 65 73 .............ces
|
||||
// 0010 61 6e 74 61 03 63 6f 6d 00 00 01 00 01 c0 0c 00 anta.com........
|
||||
// 0020 01 00 01 00 00 02 57 00 04 94 fb 36 ec ......W....6.
|
||||
uint8_t data[] = {0, 1, 0x81, 0x80, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 7, 0x63, 0x65, 0x73, 0x61, 0x6e,
|
||||
0x74, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0, 0, 1,
|
||||
0, 1, 0xc0, 0x0c, 0, 1, 0, 1, 0,
|
||||
0, 2, 0x57, 0, 4, 0x94, 0xfb, 0x36, 0xec};
|
||||
// char *data = mg_file_read("dns.bin");
|
||||
// ASSERT(data != NULL);
|
||||
ASSERT(mg_dns_parse(NULL, 0, &dm) == 0);
|
||||
ASSERT(mg_dns_parse(data, sizeof(data), &dm) == 1);
|
||||
ASSERT(strcmp(dm.name, "cesanta.com") == 0);
|
||||
data[30] = 29; // Point a pointer to itself
|
||||
memset(&dm, 0, sizeof(dm));
|
||||
ASSERT(mg_dns_parse(data, sizeof(data), &dm) == 1);
|
||||
ASSERT(strcmp(dm.name, "") == 0);
|
||||
// ASSERT(mg_dns_parse((uint8_t *) data, strlen(data), &dm) == 0);
|
||||
// free(data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user