Skip to content

Commit 1f651d1

Browse files
committed
opal/util/ethtool: fix (infamous) strncpy usage
the infamous strncpy does not NULL terminate the destination when the buffer is truncated do it ourself ! fix CID 1362576
1 parent ead7efe commit 1f651d1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

opal/util/ethtool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ opal_ethtool_get_speed (const char *if_name)
5858

5959
memset(&ifr, 0, sizeof(struct ifreq));
6060
strncpy(ifr.ifr_name, if_name, IF_NAMESIZE);
61+
/* strncpy does not null terminate when the string is truncated */
62+
ifr.ifr_name[IF_NAMESIZE-1] = '\0';
6163
ifr.ifr_data = (char *)&edata;
6264

6365
if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {

0 commit comments

Comments
 (0)