Skip to content

Commit

Permalink
Merge pull request #2587 from cesanta/tls
Browse files Browse the repository at this point in the history
Fix #2570: close only when TLS buffers drained
  • Loading branch information
scaprile authored Jan 23, 2024
2 parents 922d148 + d8fec13 commit 8dc62c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 3 additions & 5 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8dc62c2

Please sign in to comment.