From d2386bce756b615d563731b588ac237f3003f120 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 4 Sep 2008 01:09:54 +0000 Subject: [PATCH] Fix a merge problem in which name_from_addr returned pointers to the stack; found by Jiang Hong. svn:r934 --- ChangeLog | 1 + http.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bba2acca..57234596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ Changes in 1.4.8-stable: o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov. + o Fix a merge problem in which name_from_addr returned pointers to the stack; found by Jiang Hong. Changes in 1.4.7-stable: o Fix a bug where headers arriving in multiple packets were not parsed; fix from Jiang Hong; test by me. diff --git a/http.c b/http.c index 38a89b66..b6ec56fb 100644 --- a/http.c +++ b/http.c @@ -2488,6 +2488,12 @@ evhttp_get_request_connection( char *hostname = NULL, *portname = NULL; name_from_addr(sa, salen, &hostname, &portname); + if (hostname == NULL || portname == NULL) { + if (hostname) free(hostname); + if (portname) free(portname); + return (NULL); + } + event_debug(("%s: new request from %s:%s on %d\n", __func__, hostname, portname, fd)); @@ -2614,8 +2620,8 @@ name_from_addr(struct sockaddr *sa, socklen_t salen, if (ni_result != 0) return; #endif - *phost = ntop; - *pport = strport; + *phost = strdup(ntop); + *pport = strdup(strport); } /* Either connect or bind */