Skip to content

Commit 4747b27

Browse files
J. David Bryanpkoning2
authored andcommitted
SOCK: Fix buffer overreach when simplifying IPv4-mapped IPv6 addresses
1 parent 06ee4e8 commit 4747b27

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

sim_sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ if (connectaddr != NULL) {
12351235
p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
12361236
if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */
12371237
memmove(*connectaddr, 7+*connectaddr, /* prefer bare IPv4 address */
1238-
strlen(*connectaddr) - 7 + 1); /* length to include terminating \0 */
1238+
strlen(7+*connectaddr) + 1); /* length to include terminating \0 */
12391239
}
12401240

12411241
if (!(opt_flags & SIM_SOCK_OPT_BLOCKING)) {
@@ -1321,7 +1321,7 @@ int ret = 0;
13211321
ret = p_getnameinfo(addr, size, hostnamebuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
13221322
if (0 == memcmp("::ffff:", hostnamebuf, 7)) /* is this a IPv4-mapped IPv6 address? */
13231323
memmove(hostnamebuf, 7+hostnamebuf, /* prefer bare IPv4 address */
1324-
strlen(hostnamebuf) + 7 - 1); /* length to include terminating \0 */
1324+
strlen(7+hostnamebuf) + 1); /* length to include terminating \0 */
13251325
if (!ret)
13261326
ret = p_getnameinfo(addr, size, NULL, 0, portnamebuf, NI_MAXSERV, NI_NUMERICSERV);
13271327
return ret;

0 commit comments

Comments
 (0)