Skip to content

Commit

Permalink
fix(NetworkInterface): Unterminated string possible in NetworkInterfa…
Browse files Browse the repository at this point in the history
…ceImpl::setPhyParams() #3301
  • Loading branch information
aleks-f committed Jun 7, 2021
1 parent ccbdb2c commit 5219b15
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Net/src/NetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name,
void NetworkInterfaceImpl::setPhyParams()
{
#if !defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_VXWORKS)
struct ifreq ifr;
std::strncpy(ifr.ifr_name, _name.c_str(), IFNAMSIZ);
struct ifreq ifr{};
std::size_t szFrom = _name.size();
std::size_t szTo = IFNAMSIZ - 1;
std::size_t sz = szFrom <= szTo ? szFrom : szTo;
std::strncpy(ifr.ifr_name, _name.c_str(), sz);

DatagramSocket ds(SocketAddress::IPv4);

ds.impl()->ioctl(SIOCGIFFLAGS, &ifr);
Expand Down

0 comments on commit 5219b15

Please sign in to comment.