[PATCH] Truncate debug messages

Michael Santos <>
Mon Apr 12 03:24:20 CEST 2010


When the undocumented ERL_INET_GETHOST_DEBUG environment variable
is set to 5, very long hostnames can overflow the buffer used to
construct the debug message. Truncate the domain name to 255 bytes
(DOMAINNAME_MAX-3).

export ERL_INET_GETHOST_DEBUG=5
inet:gethostbyname(lists:duplicate(5000,"x")).
---
 erts/etc/common/inet_gethost.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c
index ff16ee0..17f83e2 100644
--- a/erts/etc/common/inet_gethost.c
+++ b/erts/etc/common/inet_gethost.c
@@ -1746,7 +1746,7 @@ static int worker_loop(void)
 	}
 	proto = get_proto(req);
 	data = get_data(req);
-	DEBUGF(4,("Worker got request, op = %d, proto = %d, data = %s.",
+	DEBUGF(4,("Worker got request, op = %d, proto = %d, data = %.255s.",
 		  op,proto,data));
 	/* Got a request, lets go... */
 	switch (op) {
@@ -1762,14 +1762,14 @@ static int worker_loop(void)
 		hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG);
 		hints.ai_socktype = SOCK_STREAM;
 		hints.ai_family = AF_INET6;
-		DEBUGF(5, ("Starting getaddrinfo(%s, ...)", data));
+		DEBUGF(5, ("Starting getaddrinfo(%.255s, ...)", data));
 		error_num = getaddrinfo((char *)data, NULL, &hints, &ai);
 		DEBUGF(5,("getaddrinfo returned %d", error_num));
 		if (error_num) {
 		    error_num = map_netdb_error_ai(error_num);
 		}
 #elif defined(HAVE_GETIPNODEBYNAME) /*#ifdef HAVE_GETADDRINFO */
-		DEBUGF(5,("Starting getipnodebyname(%s)",data));
+		DEBUGF(5,("Starting getipnodebyname(%.255s)",data));
 		he = getipnodebyname(data, AF_INET6, AI_DEFAULT, &error_num);
 		if (he) {
 		    free_he = 1;
@@ -1780,7 +1780,7 @@ static int worker_loop(void)
 		    error_num = map_netdb_error(error_num);
 		}
 #elif defined(HAVE_GETHOSTBYNAME2) /*#ifdef HAVE_GETADDRINFO */
-		DEBUGF(5,("Starting gethostbyname2(%s, AF_INET6)",data));
+		DEBUGF(5,("Starting gethostbyname2(%.255s, AF_INET6)",data));
 		he = gethostbyname2((char*)data, AF_INET6);
 		if (he) {
 		    error_num = 0;
@@ -1796,7 +1796,7 @@ static int worker_loop(void)
 #endif /*ifdef HAVE_IN6 */
 	    
 	    case PROTO_IPV4: { /* switch (proto) { */
-		DEBUGF(5,("Starting gethostbyname(%s)",data));
+		DEBUGF(5,("Starting gethostbyname(%.255s)",data));
 		he = gethostbyname((char*)data);
 		if (he) {
 		    error_num = 0;
-- 
1.5.6.4



More information about the erlang-patches mailing list