Skip to content

Commit 425a4bc

Browse files
authored
Fix missing null termination of a string in Getaddrinfo() in websocket_to_posix_proxy utility. (emscripten-core#25829)
`strncpy()` is evil that if the string length exceeds the copy length, the destination string is left null-terminated. So null terminate manually.
1 parent db7c761 commit 425a4bc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tools/websocket_to_posix_proxy/src/websocket_to_posix_proxy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ void Getaddrinfo(int client_fd, uint8_t *data, uint64_t numBytes) {
14941494
r->ret = ret;
14951495
r->errno_ = errorCode;
14961496
strncpy(r->ai_canonname, ai_canonname, MAX_NODE_LEN-1);
1497+
r->ai_canonname[MAX_NODE_LEN-1] = 0; // Null terminate output string if it truncated.
14971498
r->addrCount = addrCount;
14981499

14991500
struct addrinfo *ai = res;

0 commit comments

Comments
 (0)