Skip to content

Commit

Permalink
Coverity issues in contrail-controller/agent_param.cc
Browse files Browse the repository at this point in the history
I have run Coverity on branch R5.0 and it reported the
following issues in contrail-controller/agent_param.cc:
- buffer_size_warning: Calling strncpy with a maximum size
argument of 16 bytes on destination array ifrn.ifrn_name of
size 16 bytes might leave the destination string unterminated
in agent_param.cc:ValidateInterface
- leaked_storage: Variable f going out of scope leaks the storage
it points to in agent_param.cc:ValidateInterface

Indeed, for the 1st issue, the length of std::string::c_str() may be
greater than IF_NAMESIZE. In that case, after calling strncpy, ifrn.ifrn_name
will not be a NULL-terminated string.
For the 2nd issue, we need to close the file pointer before exiting the function.

Change-Id: Iceaf2490ae224b7134a4781f894b784f016e42a3
Closes-bug: #1770169
Signed-off-by: Anda Nicolae <anicolae@lenovo.com>
  • Loading branch information
Anda Nicolae committed May 14, 2018
1 parent 144a07b commit e272d14
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vnsw/agent/init/agent_param.cc
Expand Up @@ -955,7 +955,7 @@ static bool ValidateInterface(bool test_mode, const std::string &ifname,

struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname.c_str(), IF_NAMESIZE);
strncpy(ifr.ifr_name, ifname.c_str(), IF_NAMESIZE-1);
int err = ioctl(fd, SIOCGIFFLAGS, (void *)&ifr);
close (fd);

Expand All @@ -979,6 +979,7 @@ static bool ValidateInterface(bool test_mode, const std::string &ifname,
*eth_encap = "none";
}
}
fclose(f);
}
#endif

Expand Down

0 comments on commit e272d14

Please sign in to comment.