From c2e742106f54ab6b82d9ca52d69f020b2fc9a5a7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 1 Sep 2007 12:20:49 +0000 Subject: interface: fix IPV6 hostname buffer deallocation from automatics The host buffer that hostname pointed to is no longer on the stack by the time the SECURE() message is printed. So make it static and thus accessible to all. We won't be calling this stuff in the middle of a child process/thread/task, so there's no Also, hostname is a constant string we shouldn't modify, so mark it as const char *. git-svn-id: https://svn.musicpd.org/mpd/trunk@6842 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/interface.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/interface.c') diff --git a/src/interface.c b/src/interface.c index b7704ec9a..e11266741 100644 --- a/src/interface.c +++ b/src/interface.c @@ -254,7 +254,6 @@ static void closeInterface(Interface * interface) void openAInterface(int fd, struct sockaddr *addr) { - char *hostname; int i; for (i = 0; i < interface_max_connections @@ -264,28 +263,24 @@ void openAInterface(int fd, struct sockaddr *addr) ERROR("Max Connections Reached!\n"); xclose(fd); } else { + const char *hostname; switch (addr->sa_family) { case AF_INET: - { - char *host = inet_ntoa(((struct sockaddr_in *) - addr)->sin_addr); - if (host) { - hostname = host; - } else { - hostname = "error getting ipv4 address"; - } - } + hostname = (const char *)inet_ntoa(((struct sockaddr_in *) + addr)->sin_addr); + if (!hostname) + hostname = "error getting ipv4 address"; break; #ifdef HAVE_IPV6 case AF_INET6: { - char host[INET6_ADDRSTRLEN + 1]; + static char host[INET6_ADDRSTRLEN + 1]; memset(host, 0, INET6_ADDRSTRLEN + 1); if (inet_ntop(AF_INET6, (void *) &(((struct sockaddr_in6 *)addr)-> sin6_addr), host, INET6_ADDRSTRLEN)) { - hostname = host; + hostname = (const char *)host; } else { hostname = "error getting ipv6 address"; } -- cgit v1.2.3