Skip to content

Commit

Permalink
Coverity issues in pkt0_interface.cc
Browse files Browse the repository at this point in the history
buffer_size_warning: Calling strncpy with a maximum size argument of 16 bytes
on destination array ifr.ifr_name of size 16 bytes might leave the destination
string unterminated.

Change-Id: I01a7f2cf67a20a79e1e29e0f6497d523186387ce
Closes-Bug: #1770113
Signed-off-by: Anda Nicolae <anicolae@lenovo.com>
  • Loading branch information
Anda Nicolae committed Jun 5, 2018
1 parent 7cb8289 commit d8f42c5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/vnsw/agent/contrail/linux/pkt0_interface.cc
Expand Up @@ -44,7 +44,7 @@ void Pkt0Interface::InitControlInterface() {
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(tap_fd_, TUNSETIFF, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " <<
strerror(errno) << "> creating " << name_ << "tap-device");
Expand All @@ -66,7 +66,7 @@ void Pkt0Interface::InitControlInterface() {
}

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(tap_fd_, SIOCGIFHWADDR, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " << strerror(errno) <<
"> retrieving MAC address of the tap interface");
Expand All @@ -82,7 +82,7 @@ void Pkt0Interface::InitControlInterface() {
}

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name_.data(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(raw, SIOCGIFINDEX, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " <<
strerror(errno) << "> getting ifindex of the tap interface");
Expand All @@ -103,7 +103,7 @@ void Pkt0Interface::InitControlInterface() {

// Set tx-buffer count
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(raw, SIOCGIFTXQLEN, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " << strerror(errno) <<
"> getting tx-buffer size");
Expand All @@ -121,7 +121,7 @@ void Pkt0Interface::InitControlInterface() {
}

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name_.data(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(raw, SIOCGIFFLAGS, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " <<
strerror(errno) << "> getting socket flags");
Expand Down Expand Up @@ -166,7 +166,7 @@ void Pkt0RawInterface::InitControlInterface() {

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name,
pkt_handler()->agent()->pkt_interface_name().c_str(), IF_NAMESIZE);
pkt_handler()->agent()->pkt_interface_name().c_str(), IF_NAMESIZE-1);
if (ioctl(raw_, SIOCGIFINDEX, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " <<
strerror(errno) << "> getting ifindex of the " <<
Expand All @@ -187,7 +187,7 @@ void Pkt0RawInterface::InitControlInterface() {
}

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name_.data(), IF_NAMESIZE);
strncpy(ifr.ifr_name, name_.c_str(), IF_NAMESIZE-1);
if (ioctl(raw_, SIOCGIFFLAGS, (void *)&ifr) < 0) {
LOG(ERROR, "Packet Tap Error <" << errno << ": " <<
strerror(errno) << "> getting socket flags");
Expand Down

0 comments on commit d8f42c5

Please sign in to comment.