summaryrefslogtreecommitdiff
path: root/test/dm/eth.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-09-26 14:08:30 -0400
committerTom Rini <trini@konsulko.com>2017-10-06 11:28:20 -0400
commite2e6daed5a801e361d03f98e2eb770ca4fccca2c (patch)
tree7856672b6ab6b17b592cf5aa8cf6eb51d12b07bb /test/dm/eth.c
parentd91062c41e1542ffb2f8590cce75fb5a2b397fdc (diff)
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 <joe.hershberger@ni.com> Cc: Simon Glass <sjg@chromium.org> Cc: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'test/dm/eth.c')
-rw-r--r--test/dm/eth.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/test/dm/eth.c b/test/dm/eth.c
index 122fab924d..67fd660ee4 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -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);