diff options
author | Eric Wong <normalperson@yhbt.net> | 2007-09-01 12:20:49 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2007-09-01 12:20:49 +0000 |
commit | c2e742106f54ab6b82d9ca52d69f020b2fc9a5a7 (patch) | |
tree | 3c32a69d419a8968fe421fe2021314ecd3f3e09a | |
parent | c5c8548ba25e7cd5ad88ea3062db1a88d1faa0a2 (diff) | |
download | mpd-c2e742106f54ab6b82d9ca52d69f020b2fc9a5a7.tar.gz mpd-c2e742106f54ab6b82d9ca52d69f020b2fc9a5a7.tar.xz mpd-c2e742106f54ab6b82d9ca52d69f020b2fc9a5a7.zip |
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
-rw-r--r-- | src/interface.c | 19 |
1 files changed, 7 insertions, 12 deletions
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"; } |