diff --git a/mongoose.c b/mongoose.c index 0469e103..df80dfc3 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2748,7 +2748,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { const char *buf = (char *) c->recv.buf + ofs; int n = mg_http_parse(buf, c->recv.len - ofs, &hm); struct mg_str *te; // Transfer - encoding header - bool is_chunked = false; + bool is_chunked = false, is_http_1_0 = false; size_t old_len = c->recv.len; if (n < 0) { // We don't use mg_error() here, to avoid closing pipelined requests @@ -2771,7 +2771,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { hm.message.len = c->recv.len - ofs; // and closes now, deliver MSG hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf); } - bool is_http_1_0 = + is_http_1_0 = hm.proto.len > 8 && mg_ncasecmp(hm.proto.buf, "HTTP/1.0", 8) == 0; // HTTP/1.0 does not use "Transfer-Encoding: chunked" if (!is_http_1_0 && @@ -14254,7 +14254,7 @@ static int mg_tls_verify_cert_signature(const struct mg_tls_cert *cert, (unsigned) cert->tbshashsz, sig, mg_uecc_secp256r1()); } else if (issuer->pubkey.len == 96) { - MG_VERBOSE(("ignore secp386 for now")); + MG_ERROR(("reject secp386 for now")); return 0; } else { MG_ERROR(("unsupported public key length: %d", issuer->pubkey.len)); diff --git a/src/http.c b/src/http.c index dc908aba..0a4d2c8c 100644 --- a/src/http.c +++ b/src/http.c @@ -1023,7 +1023,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { const char *buf = (char *) c->recv.buf + ofs; int n = mg_http_parse(buf, c->recv.len - ofs, &hm); struct mg_str *te; // Transfer - encoding header - bool is_chunked = false; + bool is_chunked = false, is_http_1_0 = false; size_t old_len = c->recv.len; if (n < 0) { // We don't use mg_error() here, to avoid closing pipelined requests @@ -1046,7 +1046,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { hm.message.len = c->recv.len - ofs; // and closes now, deliver MSG hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf); } - bool is_http_1_0 = + is_http_1_0 = hm.proto.len > 8 && mg_ncasecmp(hm.proto.buf, "HTTP/1.0", 8) == 0; // HTTP/1.0 does not use "Transfer-Encoding: chunked" if (!is_http_1_0 && diff --git a/src/tls_builtin.c b/src/tls_builtin.c index 3c1b3301..87e5945e 100644 --- a/src/tls_builtin.c +++ b/src/tls_builtin.c @@ -1539,7 +1539,7 @@ static int mg_tls_verify_cert_signature(const struct mg_tls_cert *cert, (unsigned) cert->tbshashsz, sig, mg_uecc_secp256r1()); } else if (issuer->pubkey.len == 96) { - MG_VERBOSE(("ignore secp386 for now")); + MG_ERROR(("reject secp386 for now")); return 0; } else { MG_ERROR(("unsupported public key length: %d", issuer->pubkey.len)); diff --git a/test/unit_test.c b/test/unit_test.c index 9e54a510..e7dc8602 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -73,10 +73,9 @@ static void test_match(void) { ASSERT(mg_match(mg_str_n("a__b_c", 6), mg_str_n("a*b*c", 5), NULL) == 1); { - char *ae_value = malloc(1); // Exact size for ASAN + char *ae_value = (char *) malloc(1); // Exact size for ASAN ae_value[0] = 'g'; - struct mg_str input = {ae_value, 1}; - mg_match(input, mg_str("*gzip*"), NULL); // Check for OOB + mg_match(mg_str_n(ae_value, 1), mg_str("*gzip*"), NULL); // Check for OOB free(ae_value); } @@ -1558,7 +1557,7 @@ static void test_http_client(void) { ASSERT(ok == 301 || ok == 200); mg_mgr_poll(&mgr, 0); ok = 0; -#if MG_TLS +#if MG_TLS && MG_TLS != MG_TLS_BUILTIN url = "https://cesanta.com"; opts.name = mg_url_host(url); #if MG_TLS == MG_TLS_BUILTIN @@ -1889,8 +1888,7 @@ static void test_http_parse(void) { } { - static const char *s = - "a b HTTP/1.0\na:1\nb:2\nc:3\nd:4\ne:5\nf:6\ng:7\nh:8\n\n"; + const char *s = "a b HTTP/1.0\na:1\nb:2\nc:3\nd:4\ne:5\nf:6\ng:7\nh:8\n\n"; ASSERT(mg_http_parse(s, strlen(s), &req) == (int) strlen(s)); ASSERT((v = mg_http_get_header(&req, "e")) != NULL); ASSERT(vcmp(*v, "5")); @@ -1901,16 +1899,16 @@ static void test_http_parse(void) { { // no HTTP version - static char *s = "a b\na:1\nb:2\nc:2\n\n"; + const char *s = "a b\na:1\nb:2\nc:2\n\n"; ASSERT(mg_http_parse(s, strlen(s), &req) == -1); // HTTP version s = "a b HTTP/1.0\na:1\nb:2\nc:2\n\n"; - ASSERT(mg_http_parse(s, strlen(s), &req) == strlen(s)); + ASSERT(mg_http_parse(s, strlen(s), &req) == (int) strlen(s)); // Content-Length s = "a b HTTP/1.0\nContent-Length:10\nb:2\nc:2\n\n"; - ASSERT(mg_http_parse(s, strlen(s), &req) == strlen(s)); + ASSERT(mg_http_parse(s, strlen(s), &req) == (int) strlen(s)); // duplicated Content-Length s = "a b HTTP/1.0\nContent-Length:10\nb:2\nContent-Length:20\n\n"; @@ -3654,7 +3652,7 @@ static void test_json(void) { // mg_json_get_num: parsing exponential { - double d = 0.0; + double d = 0.0, tolerance = 1e-12; json = mg_str( "{" "\"i\":1e3," @@ -3666,7 +3664,6 @@ static void test_json(void) { "\"a\":[6.123456789e3,-1e-9]," "\"bad\":\"1e3\"" "}"); - double tolerance = 1e-12; ASSERT(mg_json_get_num(json, "$.i", &d) == true); ASSERT(fabs(d - 1000.0) < tolerance); ASSERT(mg_json_get_num(json, "$.n", &d) == true); @@ -4196,9 +4193,13 @@ int main(void) { test_sntp(); DASHBOARD("sntp"); +#if MG_TLS != MG_TLS_BUILTIN s_error = false; test_mqtt(); // sorry, MQTT_LOCALHOST is also skipped DASHBOARD("mqtt"); +#else + (void) test_mqtt; +#endif s_error = false; test_http_client();