From 346474a43bacda2636f38d29fc6bd88971fb3807 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 17 Dec 2012 22:41:51 +0100 Subject: [PATCH] getnameinfo: return error if buffers are too small --- src/libproxychains.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libproxychains.c b/src/libproxychains.c index d1ecd47..02c9c22 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -397,10 +397,13 @@ int pc_getnameinfo(const struct sockaddr *sa, socklen_t salen, } else { if(hostlen) { pc_stringfromipv4((unsigned char*) &(SOCKADDR_2(*sa)), ip_buf); - strncpy(host, ip_buf, hostlen); + if(snprintf(host, hostlen, "%s", ip_buf) >= hostlen) + return EAI_OVERFLOW; + } + if(servlen) { + if(snprintf(serv, servlen, "%d", ntohs(SOCKPORT(*sa))) >= servlen) + return EAI_OVERFLOW; } - if(servlen) - snprintf(serv, servlen, "%d", ntohs(SOCKPORT(*sa))); } return ret; }