From 9a2b733732b453c073cdd0e30e405ca84541f8e8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 16 Feb 2024 12:51:35 +0100 Subject: socket: Allow NULL as address for socket_create() and socket_connect() This will connect to localhost without the need to specify localhost or 127.0.0.1 or ::1 and also makes this invulnerable to DNS rebind attacks. --- src/socket.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/socket.c b/src/socket.c index f3ea882..6f85f2f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -432,9 +432,6 @@ int socket_create(const char* addr, uint16_t port) sprintf(portstr, "%d", port); - if (!addr) { - addr = "localhost"; - } res = getaddrinfo(addr, portstr, &hints, &result); if (res != 0) { fprintf(stderr, "%s: getaddrinfo: %s\n", __func__, gai_strerror(res)); @@ -1121,11 +1118,6 @@ int socket_connect(const char *addr, uint16_t port) int flags = 0; #endif - if (!addr) { - errno = EINVAL; - return -1; - } - memset(&hints, '\0', sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; -- cgit v1.1-32-gdbae