Merge pull request #2587 from cesanta/tls

Fix #2570: close only when TLS buffers drained
This commit is contained in:
Sergio R. Caprile authored and GitHub committed 2024-01-23 14:03:33 -03:00
commit 8dc62c25ed
2 files changed
+7 -10

No files matched your search

+3 -5
View File
@@ -7299,15 +7299,13 @@ static void read_conn(struct mg_connection *c) {
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len], n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
c->rtls.size - c->rtls.len); c->rtls.size - c->rtls.len);
// MG_DEBUG(("%lu %ld", c->id, n)); // MG_DEBUG(("%lu %ld", c->id, n));
if (n == MG_IO_ERR) { if (n == MG_IO_ERR && mg_tls_pending(c) == 0 && c->rtls.len == 0) {
c->is_closing = 1; c->is_closing = 1;
} else if (n > 0) { } else {
c->rtls.len += (size_t) n; if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c); if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return; if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len); n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
} }
} else { } else {
n = recv_raw(c, buf, len); n = recv_raw(c, buf, len);
+4 -5
View File
@@ -282,15 +282,14 @@ static void read_conn(struct mg_connection *c) {
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len], n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
c->rtls.size - c->rtls.len); c->rtls.size - c->rtls.len);
// MG_DEBUG(("%lu %ld", c->id, n)); // MG_DEBUG(("%lu %ld", c->id, n));
if (n == MG_IO_ERR) { if (n == MG_IO_ERR && mg_tls_pending(c) == 0 && c->rtls.len == 0) {
// Close only if we have fully drained both raw (rtls) and TLS buffers
c->is_closing = 1; c->is_closing = 1;
} else if (n > 0) { } else {
c->rtls.len += (size_t) n; if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c); if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return; if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len); n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
} }
} else { } else {
n = recv_raw(c, buf, len); n = recv_raw(c, buf, len);