From dd6eb63b36badf627d5f28cc3c57e350e3491242 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 11 Oct 2009 21:51:51 +0000 Subject: [PATCH] Fix NSE trace printing of IPv6 addresses. The code was using a plain sockaddr instead of sockaddr_storage so it got only a fraction of the address and the inet_ntop function would look outside of the structure into adjacent memory. A scan of localhost would look like this: NSE: TCP ::a00:0:600:0:1234 > ::a00:4d2:0:0:25 | CONNECT Here, for example, that 4d2 is the port number 1234 from the other structure. Now it prints correctly: NSE: TCP ::1:1234 > ::1:25 | CONNECT --- nse_nsock.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nse_nsock.cc b/nse_nsock.cc index b46fae7d3..30118d84c 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -813,9 +813,9 @@ void l_nsock_trace(nsock_iod nsiod, const char *message, int direction) int protocol; int af; - struct sockaddr local; + struct sockaddr_storage local; - struct sockaddr remote; + struct sockaddr_storage remote; if (!nsi_is_pcap(nsiod)) { @@ -823,7 +823,7 @@ void l_nsock_trace(nsock_iod nsiod, const char *message, int direction) char *ipstring_remote = (char *) safe_malloc(sizeof(char) * INET6_ADDRSTRLEN); status = nsi_getlastcommunicationinfo(nsiod, &protocol, &af, - &local, &remote, sizeof(sockaddr)); + (sockaddr *) &local, (sockaddr *) &remote, sizeof(sockaddr_storage)); log_write(LOG_STDOUT, "%s: %s %s:%d %s %s:%d | %s\n", SCRIPT_ENGINE, IPPROTO2STR_UC(protocol),