Skip to contentSkip to conversation

macvlan: Replace strncpy() by strscpy()

PATCH Applied Gustavo A. R. Silva 3 participants 6 messages May 27, 2019 – May 29, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macvlan: Replace strncpy() by strscpy()

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

---
 drivers/net/macvlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/macvlan.c +1 -1
index 61550122b563..0ccabde8e9c9 100644
@@ -831,7 +831,7 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
-	strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
 	switch (cmd) {
Signature · 1 line
2.21.0
#1 lore raw
Quoted 21 lines · On Mon, 27 May 2019 13:38:55 -0500 "Gustavo A. R. Silva"…

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

---
 drivers/net/macvlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/macvlan.c +0 -0
index 61550122b563..0ccabde8e9c9 100644

drivers/net/macvlan.c static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 837

Quoted 8 lines
drivers/net/macvlan.c +1 -1
@@ -831,7 +831,7 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
-	strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
 	switch (cmd) {

Why not use strlcpy like all the other places IFNAMSIZ is copied?

#2 lore raw
Quoted 27 lines · Stephen Hemminger
Quoted 24 lines · On Mon, 27 May 2019 13:38:55 -0500 "Gustavo A. R. Silva"…

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

---
 drivers/net/macvlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/macvlan.c +0 -0
index 61550122b563..0ccabde8e9c9 100644
@@ -831,7 +831,7 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
Quoted 8 lines

drivers/net/macvlan.c static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 837

Quoted 5 lines
drivers/net/macvlan.c +1 -1
-	strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
 	switch (cmd) {

Why not use strlcpy like all the other places IFNAMSIZ is copied?

strlcpy() is also being deprecated.

--
Gustavo

#3 lore raw
Quoted 32 lines · On Mon, 27 May 2019 16:28:05 -0500 "Gustavo A. R. Silva"…
Quoted 31 lines · Stephen Hemminger
Quoted 28 lines · On Mon, 27 May 2019 13:38:55 -0500 "Gustavo A. R. Silva"…

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

---
 drivers/net/macvlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/macvlan.c +1 -1
index 61550122b563..0ccabde8e9c9 100644
@@ -831,7 +831,7 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
-	strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
Quoted 6 lines
Quoted 4 lines

drivers/net/macvlan.c static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 837

Quoted 1 line
drivers/net/macvlan.c +0 -0
 	switch (cmd) {  

Why not use strlcpy like all the other places IFNAMSIZ is copied?

strlcpy() is also being deprecated.

Are you going to fix all these:

$ git grep strlcpy | grep IFNAMSIZ| wc -l
47
maintainer Applied
#4 lore raw
In reply to Gustavo A. R. Silva

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 27 May 2019 13:38:55 -0500

Quoted 7 lines

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Quoted 5 lines

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

Applied.

maintainer Applied
#5 lore raw
In reply to Gustavo A. R. Silva

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 27 May 2019 13:38:55 -0500

Quoted 7 lines

The strncpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 16 bytes on destination array ifrr.ifr_ifrn.ifrn_name of size 16 bytes might leave the destination string unterminated."

Quoted 5 lines

Notice that, unlike strncpy(), strscpy() always null-terminates the destination string.

Addresses-Coverity-ID: 1445537 ("Buffer not null terminated")

Applied.