Correctly terminate the string

This commit is contained in:
Chocobo1 2015-06-24 13:30:41 +08:00
parent 7e088a9039
commit 61289d42fb
3 changed files with 3 additions and 0 deletions

View File

@ -47,6 +47,7 @@ getifaddr(const char * ifname, char * buf, int len,
return -1;
}
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
if(ioctl(s, SIOCGIFFLAGS, &ifr, &ifrlen) < 0)
{
syslog(LOG_DEBUG, "ioctl(s, SIOCGIFFLAGS, ...): %m");

View File

@ -1237,6 +1237,7 @@ SubmitServicesToMiniSSDPD(const char * host, unsigned short port) {
}
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, minissdpdsocketpath, sizeof(addr.sun_path));
addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
syslog(LOG_ERR, "connect(\"%s\"): %m", minissdpdsocketpath);
close(s);

View File

@ -274,6 +274,7 @@ GetExternalIPAddress(struct upnphttp * h, const char * action)
if(use_ext_ip_addr)
{
strncpy(ext_ip_addr, use_ext_ip_addr, INET_ADDRSTRLEN);
ext_ip_addr[INET_ADDRSTRLEN - 1] = '\0';
}
else if(getifaddr(ext_if_name, ext_ip_addr, INET_ADDRSTRLEN, NULL, NULL) < 0)
{