lwIP sockets: a UDP send crashes the VM when pbuf_alloc fails instead of returning an error
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c, erlang
调研方向
阅读src/libAtomVM/otp_socket.c中OTP_SOCKET_LWIP分支的SocketStateUDP情况,位置在do_socket_send。检查附近的套接字错误如何返回,以及pbuf_alloc失败如何处理。为NULL pbuf添加失败路径,返回适当的套接字错误,然后验证UDP发送数据过大或内存不足时会返回错误,而不是导致VM故障。
由索引模型根据 Issue 内容生成。
描述
Affected: release-0.7 at ca1583068, lwIP socket backend (RP2 port).
Not changed by #2345.
What happens
do_socket_send builds the datagram with:
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
uint8_t *bytes = (uint8_t *) p->payload;
memcpy(bytes, buf, len);
There is no NULL check. When lwIP cannot allocate the pbuf (payload larger than
the lwIP heap, or memory exhausted by a burst of datagrams), p is NULL and
the VM dereferences it: hard fault on the Pico W, instead of {error, Reason}.
How to reproduce (Pico W)
{ok, S} = socket:open(inet, dgram, udp),
Dest = #{family => inet, addr => {192, 168, 0, 1}, port => 5000},
socket:sendto(S, binary:copy(<<0>>, 60000), Dest). % larger than MEM_SIZE
The board faults. A tight loop of 1400-byte datagrams hits the same path once
the pbuf memory is exhausted.
Where
src/libAtomVM/otp_socket.c, do_socket_send, #elif OTP_SOCKET_LWIP branch,
SocketStateUDP case.
Suggested fix
Return SocketOtherError with ERR_MEM (or SocketWouldBlock, so that
socket:sendto/3 waits and retries) when pbuf_alloc returns NULL.
- 主要语言
- Erlang
- 星标
- 2.3k
- 派生
- 171
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 20
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
atomvm/AtomVM 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
lwIP sockets: a failed listen or connect leaves the socket lock held, a later close hangs forever未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 3 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 78/100
micropython/micropython#19942 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
follow-up Prio 📌
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
facebookincubator/muse-gadget-sdk#384 ·
维护者通常 5 天内回复