core: safer truncation of hostname using memcpy
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 8 May 2020 19:28:01 +0000 (21:28 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 8 May 2020 19:28:01 +0000 (21:28 +0200)
src/core/ip_addr.h

index 6fba6bf..d96cc99 100644 (file)
@@ -800,11 +800,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);