[erlang-patches] [PATCH] Truncate debug messages

Mikael Pettersson mikpe@REDACTED
Mon Apr 12 11:47:40 CEST 2010


Michael Santos writes:
 > 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.",

etc.

I believe the better solution is to replace the unsafe vsprintf()
calls in inet_gethost.c with erts_vsnprintf() calls.


More information about the erlang-patches mailing list