Fix #2570: close only when TLS buffers drained

This commit is contained in:
Sergey Lyubka
2024-01-23 11:10:15 +00:00
parent 922d148ab5
commit d8fec13d2c
2 changed files with 7 additions and 10 deletions
+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],
c->rtls.size - c->rtls.len);
// 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;
} else if (n > 0) {
c->rtls.len += (size_t) n;
} else {
if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
}
} else {
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],
c->rtls.size - c->rtls.len);
// 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;
} else if (n > 0) {
c->rtls.len += (size_t) n;
} else {
if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
}
} else {
n = recv_raw(c, buf, len);