Skip to content

Commit 14ef29a

Browse files
HuoyanlifusuRbb666
authored andcommitted
fix(netdev): 修复无网卡时 ping 命令空指针崩溃
netdev_cmd_ping 中 netdev 回退到 netdev_default 后未判空, QEMU 无网卡环境下执行 ping 直接解引用 NULL 崩溃(data abort)。 回退后增加空指针检查,提示无可用网卡并返回错误。
1 parent 69c2678 commit 14ef29a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

components/net/netdev/src/netdev.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,11 @@ int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_
13401340
if (netdev == RT_NULL)
13411341
{
13421342
netdev = netdev_default;
1343+
if (netdev == RT_NULL)
1344+
{
1345+
rt_kprintf("ping: not found default netif, please specify netdev name.\n");
1346+
return -RT_ERROR;
1347+
}
13431348
rt_kprintf("ping: not found specified netif, using default netdev %s.\n", netdev->name);
13441349
}
13451350

@@ -1412,6 +1417,12 @@ int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_
14121417
rt_thread_delay(delay_tick);
14131418
}
14141419

1420+
if (times == 0)
1421+
{
1422+
rt_kprintf("ping: send times is zero, no ping statistics.\n");
1423+
return -RT_ERROR;
1424+
}
1425+
14151426
/* print ping statistics */
14161427
loss = (uint32_t)((1 - ((float)received) / index) * 100);
14171428
avg_time = (uint32_t)(avg_time / received);

0 commit comments

Comments
 (0)