mirror of
https://github.com/simh/simh.git
synced 2026-05-02 22:22:48 +00:00
SOCK: avoid calling strcpy with overlapping arguments when converting IPv4-mapped address strings. Fixes issue #111
This commit is contained in:
@@ -1069,7 +1069,8 @@ if (connectaddr != NULL) {
|
|||||||
#ifdef AF_INET6
|
#ifdef AF_INET6
|
||||||
p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||||
if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */
|
if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */
|
||||||
strcpy(*connectaddr, 7+*connectaddr); /* prefer bare IPv4 address if possible */
|
memmove(*connectaddr, 7+*connectaddr, /* prefer bare IPv4 address */
|
||||||
|
strlen(*connectaddr) - 7 + 1); /* length to include terminating \0 */
|
||||||
#else
|
#else
|
||||||
strcpy(*connectaddr, inet_ntoa(((struct sockaddr_in *)&connectaddr)->s_addr));
|
strcpy(*connectaddr, inet_ntoa(((struct sockaddr_in *)&connectaddr)->s_addr));
|
||||||
#endif
|
#endif
|
||||||
@@ -1148,7 +1149,8 @@ int32 ret = 0;
|
|||||||
*portnamebuf = '\0';
|
*portnamebuf = '\0';
|
||||||
ret = p_getnameinfo(addr, size, hostnamebuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
ret = p_getnameinfo(addr, size, hostnamebuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||||
if (0 == memcmp("::ffff:", hostnamebuf, 7)) /* is this a IPv4-mapped IPv6 address? */
|
if (0 == memcmp("::ffff:", hostnamebuf, 7)) /* is this a IPv4-mapped IPv6 address? */
|
||||||
strcpy(hostnamebuf, 7+hostnamebuf); /* prefer bare IPv4 address if possible */
|
memmove(hostnamebuf, 7+hostnamebuf, /* prefer bare IPv4 address */
|
||||||
|
strlen(hostnamebuf) + 7 - 1); /* length to include terminating \0 */
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = p_getnameinfo(addr, size, NULL, 0, portnamebuf, NI_MAXSERV, NI_NUMERICSERV);
|
ret = p_getnameinfo(addr, size, NULL, 0, portnamebuf, NI_MAXSERV, NI_NUMERICSERV);
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user