Explorar o código

core: safer truncation of hostname using memcpy

(cherry picked from commit aac577a4655ebf09d5cbef3e1a49f72d25ea57d7)
Daniel-Constantin Mierla %!s(int64=5) %!d(string=hai) anos
pai
achega
cd6a3035c1
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  1. 4 1
      src/core/ip_addr.h

+ 4 - 1
src/core/ip_addr.h

@@ -789,11 +789,14 @@ static inline struct hostent* ip_addr2he(str* name, struct ip_addr* ip)
 	static char* p_aliases[1];
 	static char* p_addr[2];
 	static char address[16];
+	int len;
 
 	p_aliases[0]=0; /* no aliases*/
 	p_addr[1]=0; /* only one address*/
 	p_addr[0]=address;
-	strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256);
+	len = (name->len<255)?name->len:255;
+	memcpy(hostname, name->s, len);
+	hostname[len] = '\0';
 	if (ip->len>16) return 0;
 	memcpy(address, ip->u.addr, ip->len);