Module: kamailio Branch: master Commit: aac577a4655ebf09d5cbef3e1a49f72d25ea57d7 URL: https://github.com/kamailio/kamailio/commit/aac577a4655ebf09d5cbef3e1a49f72d...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-05-08T21:28:01+02:00
core: safer truncation of hostname using memcpy
---
Modified: src/core/ip_addr.h
---
Diff: https://github.com/kamailio/kamailio/commit/aac577a4655ebf09d5cbef3e1a49f72d... Patch: https://github.com/kamailio/kamailio/commit/aac577a4655ebf09d5cbef3e1a49f72d...
---
diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h index 6fba6bf147..d96cc99d0e 100644 --- a/src/core/ip_addr.h +++ b/src/core/ip_addr.h @@ -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);