Merge pull request #3025 from cesanta/ub

fix UB and possible exception trigger
This commit is contained in:
Sergio R. Caprile authored and GitHub committed 2025-03-07 13:49:37 -03:00
commit 8906b1ac0f
3 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -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;
+1 -1
View File
@@ -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) {
+1
View File
@@ -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;