Skip to contentSkip to conversation

test/dm: Fix string handling issues in the eth test

PATCH In review Tom Rini 3 participants 4 messages Sep 26, 2017 – Oct 7, 2017

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 test/dm: Fix string handling issues in the eth test

Coverity scan has identified potential buffer overruns in these tests. Correct this by zeroing our buffer and using strncpy not strcpy.

Reported-by Coverity (CID: 155462, 155463)
Cc Joe Hershberger <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
---
 test/dm/eth.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
test/dm/eth.c +5 -3
index 122fab924d6a..67fd660ee4f5 100644
@@ -110,6 +110,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
 	char ethaddr[DM_TEST_ETH_NUM][18];
 	int i;
 
+	memset(ethaddr, '\0', sizeof(ethaddr));
 	net_ping_ip = string_to_ip("1.1.2.2");
 
 	/* Prepare the test scenario */
@@ -119,7 +120,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
 		ut_assertok(device_remove(dev[i], DM_REMOVE_NORMAL));
 
 		/* Invalidate MAC address */
-		strcpy(ethaddr[i], env_get(addrname[i]));
+		strncpy(ethaddr[i], env_get(addrname[i]), 17);
 		/* Must disable access protection for ethaddr before clearing */
 		env_set(".flags", addrname[i]);
 		env_set(addrname[i], NULL);
@@ -187,7 +188,8 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 	net_ping_ip = string_to_ip("1.1.2.2");
 
 	/* Invalidate eth1's MAC address */
-	strcpy(ethaddr, env_get("eth1addr"));
+	memset(ethaddr, '\0', sizeof(ethaddr));
+	strncpy(ethaddr, env_get("eth1addr"), 17);
 	/* Must disable access protection for eth1addr before clearing */
 	env_set(".flags", "eth1addr");
 	env_set("eth1addr", NULL);
@@ -200,7 +202,7 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 
 	if (!retval) {
 		/* Invalidate eth0's MAC address */
-		strcpy(ethaddr, env_get("ethaddr"));
+		strncpy(ethaddr, env_get("ethaddr"), 17);
 		/* Must disable access protection for ethaddr before clearing */
 		env_set(".flags", "ethaddr");
 		env_set("ethaddr", NULL);
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 test/dm: Fix string handling issues in the eth test

Quoted 11 lines · Tom Rini

Coverity scan has identified potential buffer overruns in these tests. Correct this by zeroing our buffer and using strncpy not strcpy.

Reported-by Coverity (CID: 155462, 155463)
Cc Joe Hershberger <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
---
 test/dm/eth.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
#2 lore raw

PATCH 1/1 test/dm: Fix string handling issues in the eth test

In reply to Tom Rini
Quoted 8 lines · Tom Rini

Coverity scan has identified potential buffer overruns in these tests. Correct this by zeroing our buffer and using strncpy not strcpy.

Reported-by Coverity (CID: 155462, 155463)
Cc Joe Hershberger <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
author
#3 lore raw
In reply to Tom Rini
Quoted 10 lines · Tom Rini

Coverity scan has identified potential buffer overruns in these tests. Correct this by zeroing our buffer and using strncpy not strcpy.

Reported-by Coverity (CID: 155462, 155463)
Cc Joe Hershberger <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171007/1b23ee0b/attachment.sig>