Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UB and possible exception trigger #3025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -4731,7 +4731,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) {
Expand Down Expand Up @@ -11341,6 +11341,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;
Expand Down
2 changes: 1 addition & 1 deletion src/net_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/tls_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,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;
Expand Down
Loading