diff --git a/mongoose.c b/mongoose.c index 501b0a3b..acefc897 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4732,7 +4732,7 @@ static void handle_tls_recv(struct mg_connection *c) { mg_error(c, "oom"); } else { // Decrypt data directly into c->recv - long n = mg_tls_recv(c, &io->buf[io->len], io->size - io->len); + long n = mg_tls_recv(c, io->buf != NULL ? &io->buf[io->len] : io->buf, io->size - io->len); if (n == MG_IO_ERR) { mg_error(c, "TLS recv error"); } else if (n > 0) { @@ -12005,6 +12005,7 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { mg_tls_drop_record(c); return MG_IO_WAIT; } + if (buf == NULL || len == 0) return 0L; minlen = len < tls->recv_len ? len : tls->recv_len; memmove(buf, recv_buf, minlen); tls->recv_offset += minlen; diff --git a/src/net_builtin.c b/src/net_builtin.c index 964681f6..c9038211 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -651,7 +651,7 @@ static void handle_tls_recv(struct mg_connection *c) { mg_error(c, "oom"); } else { // Decrypt data directly into c->recv - long n = mg_tls_recv(c, &io->buf[io->len], io->size - io->len); + long n = mg_tls_recv(c, io->buf != NULL ? &io->buf[io->len] : io->buf, io->size - io->len); if (n == MG_IO_ERR) { mg_error(c, "TLS recv error"); } else if (n > 0) { diff --git a/src/tls_builtin.c b/src/tls_builtin.c index a7a587f7..31026b98 100644 --- a/src/tls_builtin.c +++ b/src/tls_builtin.c @@ -1712,6 +1712,7 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { mg_tls_drop_record(c); return MG_IO_WAIT; } + if (buf == NULL || len == 0) return 0L; minlen = len < tls->recv_len ? len : tls->recv_len; memmove(buf, recv_buf, minlen); tls->recv_offset += minlen;