assorted patches

This commit is contained in:
Sergio R. Caprile authored and Sergio R. Caprile committed 2026-06-23 13:38:35 -03:00
1 parent 07a49a7a2d
commit a9df523f76
34 files changed
+1240 -592

No files matched your search

+9 -6
View File
@@ -1,8 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBFTCBvAIJAMNTFtpfcq8NMAoGCCqGSM49BAMCMBMxETAPBgNVBAMMCE1vbmdv
b3NlMB4XDTI0MDUwNzE0MzczNloXDTM0MDUwNTE0MzczNlowEzERMA8GA1UEAwwI
TW9uZ29vc2UwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASuP+86T/rOWnGpEVhl
fxYZ+pjMbCmDZ+vdnP0rjoxudwRMRQCv5slRlDK7Lxue761sdvqxWr0Ma6TFGTNg
epsRMAoGCCqGSM49BAMCA0gAMEUCIQCwb2CxuAKm51s81S6BIoy1IcandXSohnqs
us64BAA7QgIgGGtUrpkgFSS0oPBlCUG6YPHFVw42vTfpTC0ySwAS0M4=
MIIBizCCATGgAwIBAgIUCeZlJSIxVY+xQGNhIXY42jph+SYwCgYIKoZIzj0EAwIw
EzERMA8GA1UEAwwITW9uZ29vc2UwHhcNMjYwNjE2MTcyMDI3WhcNMzYwNjEzMTcy
MDI3WjATMREwDwYDVQQDDAhNb25nb29zZTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABK4/7zpP+s5acakRWGV/Fhn6mMxsKYNn692c/SuOjG53BExFAK/myVGUMrsv
G57vrWx2+rFavQxrpMUZM2B6mxGjYzBhMB0GA1UdDgQWBBRVNi9ypHsbLJh/hZwm
/IO+lYcIujAfBgNVHSMEGDAWgBRVNi9ypHsbLJh/hZwm/IO+lYcIujAPBgNVHRMB
Af8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAKBggqhkjOPQQDAgNIADBFAiB7A6qe
3N9QNxYWDYMGgUSYlQr+V2ShL/eOIZcxLt/vQAIhALwYVw/W8n8H3grXtx1Gby+u
97aiTxPGbssyw6YShpaG
-----END CERTIFICATE-----
+5 -2
View File
@@ -12,9 +12,12 @@ subjectAltName=DNS:localhost
EOF
# Generate CA
# Important: CN names must be different for CA and client/server certs
# Important: CN names must be different for CA and client/server certs;
# extensions are required for a proper CA certificate
openssl ecparam -noout -name prime256v1 -genkey -out ca.key
openssl req -x509 -new -key ca.key -days 3650 -subj /CN=Mongoose -out ca.crt
openssl req -x509 -new -key ca.key -days 3650 -subj /CN=Mongoose \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" -out ca.crt
# Generate server cert
openssl ecparam -noout -name prime256v1 -genkey -out server.key
+175 -58
View File
@@ -1267,10 +1267,17 @@ static void test_http_server(void) {
}
// Directory listing
fetch(&mgr, buf, url, "GET /dirtest/ HTTP/1.0\n\n");
#if MG_ARCH == MG_ARCH_UNIX
ASSERT(system("touch 'dirtest/a<b&c>.txt'") == 0);
#endif
ASSERT(fetch(&mgr, buf, url, "GET /dirtest/ HTTP/1.0\n\n") == 200);
MG_DEBUG(("%s", buf));
ASSERT(mgstrstr(mg_str(buf), mg_str(">Index of /dirtest/<")) != NULL);
ASSERT(mgstrstr(mg_str(buf), mg_str(">fuzz.c<")) != NULL);
#if MG_ARCH == MG_ARCH_UNIX
ASSERT(mgstrstr(mg_str(buf), mg_str(">a&lt;b&amp;c&gt;.txt<")) != NULL);
if (system("rm 'dirtest/a<b&c>.txt'") == 0) (void) 0;
#endif
ASSERT(cmpheader(buf, "A", "B"));
ASSERT(!cmpheader(buf, "C", "D"));
ASSERT(cmpheader(buf, "E", "F"));
@@ -1749,6 +1756,14 @@ static void test_http_parse(void) {
ASSERT(req.body.len == 0);
}
{
const char *s = "GET / HTTP/1.0\r\nHost: test\r\n"
"Transfer-Encoding: chunked\r\n\r\n";
mg_http_parse(s, strlen(s), &req);
ASSERT(req.proto.len == 8 &&
mg_strcmp(req.proto, mg_str("HTTP/1.0")) == 0);
}
{
const char *s = "GET / \r\n";
ASSERT(mg_http_parse(s, strlen(s), &req) == 0);
@@ -1979,10 +1994,25 @@ static void test_http_parse(void) {
{
// Test that query-string gets stripped
struct mg_http_message hm;
const char *s = "GET /foo?bar HTTP/1.0\n\n";
const char *s = "GET /foo?bar HTTP/1.1\n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
ASSERT(mg_strcmp(hm.uri, mg_str("/foo")) == 0);
ASSERT(mg_strcmp(hm.query, mg_str("bar")) == 0);
s = "POST / HTTP/1.1\r\nHost: t\r\n"
"Content-Length: 5\r\nContent-Length: 10\r\n\r\n";
ASSERT(mg_http_parse(s, strlen(s), &req) == -1);
s = "POST / HTTP/1.1\r\nHost: t\r\n"
"Transfer-Encoding: chunked\r\nTransfer-Encoding: identity\r\n\r\n";
ASSERT(mg_http_parse(s, strlen(s), &req) == -1);
s = "POST / HTTP/1.1\r\nHost: t\r\n"
"Content-Length: 5\r\nTransfer-Encoding: chunked\r\n\r\n";
ASSERT(mg_http_parse(s, strlen(s), &req) == -1);
s = "POST / HTTP/1.1\r\nHost: t\r\n"
"Transfer-Encoding: chunked\r\nContent-Length: 5\r\n\r\n";
ASSERT(mg_http_parse(s, strlen(s), &req) == -1);
}
}
@@ -2450,15 +2480,23 @@ static void test_str(void) {
TESTDOUBLE("%g", -987.65432, "-987.654");
TESTDOUBLE("%g", 0.0000000001, "1e-10");
TESTDOUBLE("%g", 2.34567e-57, "2.34567e-57");
TESTDOUBLE("%.*g", DBLWIDTH(7, 9999999.0), "9999999");
TESTDOUBLE("%.*g", DBLWIDTH(10, 0.123456333), "0.123456333");
TESTDOUBLE("%g", -2.34567e-57, "-2.34567e-57");
TESTDOUBLE("%g", 123.456222, "123.456");
TESTDOUBLE("%.*g", DBLWIDTH(10, 123.456222), "123.456222");
TESTDOUBLE("%g", 600.1234, "600.123");
TESTDOUBLE("%g", -600.1234, "-600.123");
TESTDOUBLE("%g", 599.1234, "599.123");
TESTDOUBLE("%g", -599.1234, "-599.123");
TESTDOUBLE("%g", 0.14, "0.14");
TESTDOUBLE("%.*g", DBLWIDTH(7, 9999999.0), "9999999");
TESTDOUBLE("%.*g", DBLWIDTH(10, 0.123456333), "0.123456333");
TESTDOUBLE("%.*g", DBLWIDTH(10, 123.456222), "123.456222");
TESTDOUBLE("%.*g", DBLWIDTH(10, 1e11), "1e+11"); // e > width
TESTDOUBLE("%.*g", DBLWIDTH(10, -1e11), "-1e+11"); // -e < -width
{
struct mg_iobuf io = {0, 0, 0, 16};
mg_xprintf(mg_pfn_iobuf, &io, "%.*g", 88, -1e-88); // > sizeof(tmp)
mg_iobuf_free(&io);
}
TESTDOUBLE("%f", 0.14, "0.140000");
TESTDOUBLE("%.*f", DBLWIDTH(4, 0.14), "0.1400");
TESTDOUBLE("%.*f", DBLWIDTH(3, 0.14), "0.140");
@@ -2974,7 +3012,7 @@ static void uc(struct mg_connection *c, int ev, void *ev_data) {
// c->is_hexdumping = 1;
} else if (ev == MG_EV_CONNECT) {
mg_printf(c,
"POST /upload HTTP/1.0\r\n"
"POST /upload HTTP/1.1\r\n"
"Transfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "%s", "foo\n");
mg_http_printf_chunk(c, "%s", "bar\n");
@@ -3272,7 +3310,19 @@ static void test_multipart(void) {
"hello world\r\n"
"\r\n"
"--xyz--\r\n";
const char *bad_multipart =
"--xyz\r\n"
"Content-Disposition: form-data; name=\"foo\"; filename=\"safe\rname.txt\"\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"hello\r\n"
"--xyz--\r\n";
ASSERT(mg_http_next_multipart(mg_str(""), 0, NULL) == 0);
ASSERT(mg_http_next_multipart(mg_str(bad_multipart), 0, &part) > 0);
ASSERT(mg_strcmp(part.name, mg_str("foo")) == 0);
ASSERT(mg_strcmp(part.filename, mg_str("safe\rname.txt")) == 0);
ASSERT(mg_strcmp(part.body, mg_str("hello")) == 0);
ASSERT((ofs = mg_http_next_multipart(mg_str(s), 0, &part)) > 0);
ASSERT(mg_strcmp(part.name, mg_str("val")) == 0);
// MG_INFO(("--> [%.*s]", (int) part.body.len, part.body.buf));
@@ -3487,9 +3537,13 @@ static void test_rewrites(void) {
static void test_get_header_var(void) {
struct mg_str empty = mg_str(""), bar = mg_str("bar"), baz = mg_str("baz");
struct mg_str header = mg_str("Digest foo=\"bar\", blah,boo=baz, x=\"yy\"");
struct mg_str bad_header = mg_str("Digest foo=\"bar");
struct mg_str yy = mg_str("yy");
// struct mg_str x = mg_http_get_header_var(header, mg_str("x"));
// MG_INFO(("--> [%d] [%d]", (int) x.len, yy.len));
struct mg_str bad_value = mg_http_get_header_var(bad_header, mg_str("foo"));
ASSERT(bad_value.len == 4);
ASSERT(mg_strcmp(mg_str("\"bar"), bad_value) == 0);
ASSERT(mg_strcmp(empty, mg_http_get_header_var(empty, empty)) == 0);
ASSERT(mg_strcmp(empty, mg_http_get_header_var(header, empty)) == 0);
ASSERT(mg_strcmp(empty, mg_http_get_header_var(header, mg_str("fooo"))) == 0);
@@ -4134,57 +4188,116 @@ static void test_x25519(void) {
static void test_rsa(void) {
#if MG_TLS == MG_TLS_BUILTIN
const unsigned char mod[] = {
0x00, 0xba, 0xee, 0x3b, 0x0b, 0x89, 0x58, 0xa6, 0x19, 0x0d, 0x4c, 0x89,
0x1a, 0x85, 0x9a, 0xf4, 0x55, 0xc2, 0xdd, 0x0d, 0xd4, 0x4a, 0xf5, 0xed,
0xda, 0x28, 0x55, 0x2f, 0x64, 0x46, 0x21, 0x9f, 0x46, 0x5c, 0xfa, 0x37,
0x88, 0x11, 0xdf, 0xcb, 0x51, 0x73, 0x42, 0x3d, 0x5e, 0x50, 0xde, 0x11,
0x30, 0x61, 0x04, 0x59, 0xd0, 0xf4, 0x57, 0xed, 0x13, 0x90, 0x32, 0xc5,
0x3f, 0xe6, 0x66, 0xfc, 0x2a, 0x12, 0xa3, 0x1f, 0xd1, 0x77, 0x21, 0x65,
0xdf, 0x9a, 0xcf, 0x04, 0x05, 0xc3, 0x1c, 0xf8, 0x79, 0xb5, 0xf5, 0x97,
0x68, 0x98, 0x2e, 0x96, 0x85, 0x3f, 0xee, 0x71, 0x91, 0xc1, 0x54, 0x71,
0x9a, 0x80, 0x1f, 0xbe, 0x21, 0xd9, 0xc1, 0x80, 0x9b, 0xd0, 0x5d, 0xb3,
0x76, 0x3e, 0xcc, 0x14, 0x3d, 0xec, 0xb7, 0x18, 0x74, 0xfb, 0xc4, 0x0e,
0x56, 0x8d, 0x3d, 0x78, 0xe6, 0xca, 0xcd, 0x9d, 0xc6, 0x20, 0x5a, 0xeb,
0x9b, 0xc8, 0x19, 0x5e, 0xeb, 0x80, 0xd2, 0xb2, 0xfe, 0x88, 0x15, 0x5c,
0x7c, 0x6b, 0x26, 0xe0, 0x43, 0xda, 0xa4, 0x07, 0x85, 0x73, 0xc4, 0x80,
0x28, 0xcb, 0xda, 0x18, 0x56, 0x37, 0x91, 0xd6, 0x41, 0xa1, 0x0b, 0xa2,
0x77, 0xd0, 0x62, 0x31, 0xc7, 0xc2, 0x67, 0x6d, 0x75, 0x08, 0x80, 0xe7,
0xb6, 0xbe, 0xc2, 0x25, 0xc9, 0xe0, 0x2c, 0x02, 0xbf, 0x39, 0x61, 0x7e,
0x32, 0xa4, 0xc9, 0xe7, 0x91, 0xe3, 0xa0, 0xcd, 0x94, 0x24, 0xbf, 0x8c,
0xeb, 0x47, 0x76, 0x53, 0x85, 0xb3, 0xb7, 0x31, 0x80, 0x3c, 0x77, 0x10,
0x69, 0xc3, 0x04, 0xd1, 0x60, 0x4c, 0x74, 0xda, 0x15, 0x18, 0x0b, 0x20,
0x6f, 0xb3, 0x03, 0x58, 0x4a, 0xfc, 0xd1, 0xd2, 0xcf, 0x37, 0x15, 0x0a,
0x63, 0xc8, 0xe9, 0xd5, 0x7d, 0xd5, 0xf2, 0x90, 0x78, 0x53, 0x49, 0xa9,
0xc5, 0x25, 0x65, 0x5c, 0x01};
const unsigned char exp[] = {1, 0, 1}; // 65537
const unsigned char sig[] = {
0x1e, 0xb1, 0x6a, 0xcb, 0x39, 0x63, 0x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 0x1b, 0x02, 0xb3, 0x2b, 0x1d, 0x44, 0xac, 0x30, 0x81, 0xd3, 0x11,
0xdd, 0x34, 0x1e, 0xcd, 0x26, 0xf5, 0x89, 0xc6, 0x55, 0x23, 0x17, 0x09,
0xd2, 0xc1, 0xdc, 0x49, 0xf9, 0x99, 0x36, 0x2b, 0xf5, 0xae, 0x42, 0x5c,
0xb7, 0x80, 0xda, 0x32, 0x69, 0x28, 0xa3, 0xee, 0xb9, 0xd4, 0x90, 0xa6,
0xab, 0x34, 0x17, 0x5e, 0xa0, 0xd6, 0xc1, 0x54, 0xc6, 0x9c, 0x58, 0x3a,
0xaf, 0xbf, 0xdc, 0x64};
unsigned char v[256]; // 2048 bits
mg_rsa_mod_pow(mod, sizeof(mod), exp, sizeof(exp), sig, sizeof(sig), v,
sizeof(v));
ASSERT(v[sizeof(v) - 1] == 0xbc);
static const uint8_t tv_n[256] = {
0xe5, 0xd5, 0x5c, 0xed, 0xa7, 0xeb, 0xdd, 0x7f, 0x2a, 0x23, 0xd3, 0x2b,
0xd1, 0x01, 0x4e, 0xd3, 0x06, 0x51, 0x8a, 0x7f, 0x49, 0xaa, 0x1d, 0xa0,
0x6b, 0xa4, 0x75, 0x2d, 0x88, 0x99, 0x12, 0x20, 0x56, 0x43, 0x4a, 0x32,
0x52, 0xa4, 0x92, 0x4f, 0x9e, 0xae, 0x73, 0x7e, 0x22, 0x78, 0x8e, 0xec,
0x64, 0x0a, 0xff, 0xeb, 0x02, 0x9e, 0xfe, 0x0c, 0xbf, 0x37, 0x4e, 0xf9,
0xb3, 0x71, 0x23, 0x29, 0xae, 0x22, 0xc9, 0x9e, 0xa3, 0xc9, 0x63, 0xa8,
0x89, 0x39, 0x89, 0xf0, 0x37, 0x27, 0x1a, 0xbf, 0x9b, 0x70, 0x35, 0xf2,
0x7c, 0x0f, 0x34, 0xf2, 0x80, 0x6b, 0x9b, 0x80, 0x98, 0x16, 0x64, 0xba,
0x7e, 0x51, 0x22, 0xe1, 0xca,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 0xf0, 0xd7, 0xa4, 0xb3, 0x38, 0x04, 0xcc, 0x7f,
0x45, 0xba, 0x05, 0x26, 0xf9, 0x34, 0x50, 0xb4, 0xcf, 0xf3, 0x81, 0xb7,
0xf9, 0xf1, 0x2a, 0xbc, 0x2e, 0xe1, 0x51, 0x12, 0x23, 0x5a, 0xec, 0xe8,
0x59, 0x1b, 0xb2, 0x58, 0x6e, 0x17, 0x3c, 0x9e, 0x3a, 0x24, 0xf2, 0x7d,
0xd8, 0xfa, 0x82, 0xf5, 0x30, 0x13, 0x53, 0xf5, 0x6e, 0x08, 0xdd, 0x0d,
0x92, 0x24, 0x84, 0x02, 0x7b, 0x64, 0x55, 0x1c, 0xda, 0xf4, 0xb7, 0xc1,
0x35, 0x87, 0xd2, 0x79, 0xf4, 0x34, 0xc3, 0xb7, 0x58, 0xdb, 0x8b, 0x82,
0x71, 0x49, 0xc1, 0x85, 0x7f, 0x56, 0x8a, 0xf7, 0xaf, 0xbb, 0xd6, 0x38,
0x38, 0x34, 0x4b, 0x93, 0xe9, 0x77, 0x37, 0xd0, 0x9c, 0xd2, 0xe0, 0x76,
0x6f, 0xa2, 0x20, 0x2e, 0x0a, 0x2e, 0x48, 0x5e, 0xa2, 0x83, 0xd2, 0xfa,
0xc2, 0xc8, 0xd9, 0xa7, 0xcd, 0x7b, 0xb3, 0x78, 0x30, 0x46, 0x7e, 0x83,
0xbc, 0x11, 0x40, 0xbc};
static const uint8_t tv_mhash[32] = {
0x21, 0x83, 0x9d, 0xb5, 0x7b, 0xe2, 0x84, 0xc2, 0x31, 0xf7, 0xb6,
0xa1, 0x90, 0x9b, 0x53, 0x99, 0x5f, 0x09, 0x1b, 0x84, 0xf7, 0x35,
0x57, 0xbb, 0xbb, 0xef, 0x7f, 0x7b, 0x93, 0xe8, 0xef, 0x16};
ASSERT(mg_rsa_verify(tv_em, 256, tv_mhash));
{
uint8_t em[256];
int r = mg_rsa_mod_pow(tv_n, sizeof(tv_n), tv_e, sizeof(tv_e), tv_sig,
sizeof(tv_sig), em, sizeof(em));
ASSERT(r == 0);
ASSERT(memcmp(em, tv_em, 256) == 0);
ASSERT(mg_rsa_verify(em, 256, tv_mhash));
}
{
uint8_t mhash[32];
uint8_t em[256];
memcpy(mhash, tv_mhash, 32);
memcpy(em, tv_em, 256);
mhash[0] ^= 0x01; // wrong mhash
ASSERT(!mg_rsa_verify(tv_em, 256, mhash));
mhash[0] = tv_mhash[0];
em[255] ^= 0x01; // bad trailer
ASSERT(!mg_rsa_verify(em, 256, tv_mhash));
em[255] = tv_em[255];
em[0] |= 0x80; // top bit set
ASSERT(!mg_rsa_verify(em, 256, tv_mhash));
em[0] = tv_em[0];
em[223] ^= 0xFF; // corrupt h field
ASSERT(!mg_rsa_verify(em, 256, tv_mhash));
em[223] = tv_em[223];
em[50] ^= 0x01; // corrupt zero padding
ASSERT(!mg_rsa_verify(em, 256, tv_mhash));
em[50] = tv_em[50];
}
#endif
}
@@ -5148,7 +5261,6 @@ static void test_modbus(void) {
mg_mgr_free(&mgr);
}
struct wudata {
struct mg_mgr *mgr;
unsigned long conn_id; // Parent connection ID
@@ -5192,11 +5304,16 @@ static void test_wakeup(void) {
#endif
}
extern uint64_t mg_boot_timestamp_ms;
int main(void) {
const char *debug_level = getenv("V");
if (debug_level == NULL) debug_level = "3";
mg_log_set(atoi(debug_level));
// make sure there is a time reference for mg_now() regardless of SNTP tests
mg_boot_timestamp_ms = (uint64_t) time(NULL) * 1000;
s_error = false;
test_modbus();
DASHBOARD("modbus");