[lwip][ppp]: fix the risk of name member contamination in the ppp netif#11410
[lwip][ppp]: fix the risk of name member contamination in the ppp netif#11410Evlers wants to merge 2 commits into
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
| static err_t ppp_netif_init_cb(struct netif *netif) { | ||
| netif->name[0] = 'p'; | ||
| netif->name[1] = 'p'; | ||
| strncpy(netif->name, "pp", sizeof(netif->name)); |
There was a problem hiding this comment.
2.0.3的一起修改下?
There was a problem hiding this comment.
而且我看这个PR修改的是LWIP源码,看了下官方上游也是这么写的,感觉这么改不是很好
感觉应该从软件包上着手修改下
There was a problem hiding this comment.
其实可以在ppp-device中,修改所有的class,将ppp_device = rt_malloc(sizeof(struct ppp_device));改为ppp_device = rt_calloc(1, sizeof(struct ppp_device));就可以解决。但是这样需要依赖ppp-device软件包去确保name不会被污染,感觉不够稳妥。
There was a problem hiding this comment.
另外,因为是lwip的代码,所以我没用上rtthread的rt_strncpy,而是strncpy。
不过里面已经引用了rtthread,那使用rt_strncpy也合理
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-05-23 11:31 CST)
📝 Review Instructions
|
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
在
ppp_device_register的ppp_device参数如果在使用rt_malloc而非rt_calloc的情况下,name成员很大概率是非0状态,netdev_get_by_name中使用rt_strncmp比较时无法匹配对应网卡返回NULL导致断言。你的解决方案是什么 (what is your solution)
在
ppp_netif_init_cb中使用strncpy重新刷洗name成员保证使用\0结尾RT_LWIP_NETIF_NAMESIZE最小为3,确保strncpy能够写入\0到name中请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up