mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
reject improper TLS record lengths
This commit is contained in:
1 parent
2b0a5e9701
commit
a561f3e096
2 files changed
+16
-6
No files matched your search
+8
-3
@@ -16819,9 +16819,14 @@ static void mg_der_debug(struct mg_der_tlv *tlv, int depth) {
|
|||||||
|
|
||||||
// Did we receive a full TLS record in the c->rtls buffer?
|
// Did we receive a full TLS record in the c->rtls buffer?
|
||||||
static bool mg_tls_got_record(struct mg_connection *c) {
|
static bool mg_tls_got_record(struct mg_connection *c) {
|
||||||
return c->rtls.len >= (size_t) TLS_RECHDR_SIZE &&
|
uint16_t rl;
|
||||||
c->rtls.len >=
|
if (c->rtls.len < (size_t) TLS_RECHDR_SIZE) return false;
|
||||||
(size_t) (TLS_RECHDR_SIZE + MG_LOAD_BE16(c->rtls.buf + 3));
|
rl = MG_LOAD_BE16(c->rtls.buf + 3);
|
||||||
|
if (rl > 16384 + 256) { // TLS 1.3 record max length (RFC-9846 5.1)
|
||||||
|
mg_error(c, "TLS record too large");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return c->rtls.len >= (size_t) (TLS_RECHDR_SIZE + rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a single TLS record from the recv buffer
|
// Remove a single TLS record from the recv buffer
|
||||||
|
|||||||
+8
-3
@@ -267,9 +267,14 @@ static void mg_der_debug(struct mg_der_tlv *tlv, int depth) {
|
|||||||
|
|
||||||
// Did we receive a full TLS record in the c->rtls buffer?
|
// Did we receive a full TLS record in the c->rtls buffer?
|
||||||
static bool mg_tls_got_record(struct mg_connection *c) {
|
static bool mg_tls_got_record(struct mg_connection *c) {
|
||||||
return c->rtls.len >= (size_t) TLS_RECHDR_SIZE &&
|
uint16_t rl;
|
||||||
c->rtls.len >=
|
if (c->rtls.len < (size_t) TLS_RECHDR_SIZE) return false;
|
||||||
(size_t) (TLS_RECHDR_SIZE + MG_LOAD_BE16(c->rtls.buf + 3));
|
rl = MG_LOAD_BE16(c->rtls.buf + 3);
|
||||||
|
if (rl > 16384 + 256) { // TLS 1.3 record max length (RFC-9846 5.1)
|
||||||
|
mg_error(c, "TLS record too large");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return c->rtls.len >= (size_t) (TLS_RECHDR_SIZE + rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a single TLS record from the recv buffer
|
// Remove a single TLS record from the recv buffer
|
||||||
|
|||||||
Reference in new issue
Block a user