Skip to content

Commit

Permalink
Dynamically allocate memory for SSL writev
Browse files Browse the repository at this point in the history
NET_MAX_WRITES_PER_EVENT(64K) is quite a large memory, using such
size of memory on stack is quite dangerous. On the other hand,
once NET_MAX_WRITES_PER_EVENT becomes larger in someday, this may
become mine field.

Signed-off-by: zhenwei pi <[email protected]>
  • Loading branch information
pizhenwei committed Jan 8, 2024
1 parent ca1f67a commit 6cfb5b5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,16 @@ static int connTLSWritev(connection *conn_, const struct iovec *iov, int iovcnt)
* which is worth doing more memory copies in exchange for fewer system calls,
* so concatenate these scattered buffers into a contiguous piece of memory
* and send it away by one call to connTLSWrite(). */
char buf[iov_bytes_len];
char *buf = zmalloc(iov_bytes_len);
size_t offset = 0;
for (int i = 0; i < iovcnt; i++) {
memcpy(buf + offset, iov[i].iov_base, iov[i].iov_len);
offset += iov[i].iov_len;
}
return connTLSWrite(conn_, buf, iov_bytes_len);
int ret = connTLSWrite(conn_, buf, iov_bytes_len);

zfree(buf);
return ret;
}

static int connTLSRead(connection *conn_, void *buf, size_t buf_len) {
Expand Down

0 comments on commit 6cfb5b5

Please sign in to comment.