Fix mg_sntp_parse()

This commit is contained in:
cpq committed 2020-12-11 13:16:51 +00:00
1 parent 1b551741b8
commit 30d4a1ad0f
5 files changed
+19 -4

No files matched your search

+7
View File
@@ -4,25 +4,32 @@
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
struct mg_dns_message dm;
mg_dns_parse(data, size, &dm);
mg_dns_parse(NULL, 0, &dm);
struct mg_http_message hm;
mg_http_parse((const char *) data, size, &hm);
mg_http_parse(NULL, 0, &hm);
struct mg_str body = mg_str_n((const char *) data, size);
char tmp[256];
mg_http_get_var(&body, "key", tmp, sizeof(tmp));
mg_url_decode((char *) data, size, tmp, sizeof(tmp), 1);
mg_url_decode((char *) data, size, tmp, 1, 1);
mg_url_decode(NULL, 0, tmp, 1, 1);
struct mg_mqtt_message mm;
mg_mqtt_parse(data, size, &mm);
mg_mqtt_parse(NULL, 0, &mm);
struct timeval tv;
mg_sntp_parse(data, size, &tv);
mg_sntp_parse(NULL, 0, &tv);
char buf[size * 4 / 3 + 5]; // At least 4 chars and nul termination
mg_base64_decode((char *) data, size, buf);
mg_base64_decode(NULL, 0, buf);
mg_base64_encode(data, size, buf);
mg_base64_encode(NULL, 0, buf);
return 0;
}
+9 -1
View File
@@ -247,6 +247,8 @@ static void test_sntp(void) {
ASSERT(tm->tm_sec == 21);
ASSERT(mg_sntp_parse(bad_good, sizeof(bad_good), &tv) == -1);
}
ASSERT(mg_sntp_parse(NULL, 0, &tv) == -1);
}
static void mqtt_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
@@ -860,6 +862,11 @@ static void test_str(void) {
ASSERT(mg_strcmp(mg_str("hi"), mg_strstrip(mg_str(" \thi\r\n"))) == 0);
}
static void test_dns(void) {
struct mg_dns_message dm;
ASSERT(mg_dns_parse(NULL, 0, &dm) == 0);
}
static void test_util(void) {
char buf[100], *s = mg_hexdump("abc", 3);
ASSERT(s != NULL);
@@ -876,6 +883,8 @@ static void test_util(void) {
int main(void) {
mg_log_set("3");
test_util();
test_sntp();
test_dns();
test_mqtt();
test_str();
test_timer();
@@ -893,7 +902,6 @@ int main(void) {
test_http_client();
test_http_no_content_length();
test_http_pipeline();
test_sntp();
printf("SUCCESS. Total tests: %d\n", s_num_tests);
return EXIT_SUCCESS;
}