Repository navigation
fix: correct eight bugs found in STM32Ethernet sources - #102
Merged
Merged
Conversation
The accepted flag is read after the accept logic but was never set on every path, so it could hold an indeterminate value. Changing it to a boolean type and initializing it to false. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
When mem_malloc() fails for the new connection structure, the error path called tcp_connection_close() with a NULL client and dereferenced it. Close only the new pcb with tcp_close(), since there is no client structure to update. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
_stm32_eth_scheduler() was declared and defined only for STM32 cores newer than 0x01060100, but scheduler_callback() calls it unconditionally, so older cores failed to build. Define it for all versions and keep the stm32_eth_scheduler() wrapper for the newer timer path. Older cores get a wrapper that calls the shared body from the polling loops. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
operator== read _tcp_client->pcb without checking for NULL. Two clients with no connection both have a NULL _tcp_client, so comparing them crashed. Only compare the pcb when both have one. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
stop() freed _tcp_client unconditionally, but a client created from a server-owned tcp_struct does not own it. EthernetServer::accept() frees those slots, so the same memory was freed twice. Track ownership with _owns_tcp_client, set only in connect(), and free only owned connections. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
begin() returned 0 after a failed igmp_joingroup() but left the UDP pcb allocated and bound. Call stop() before returning so the socket is not leaked. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
write(buffer, size) assigned the result of stm32_new_data() directly to _data. On allocation failure that dropped the packet already buffered. Store the result in a temporary and assign _data only on success. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
The default constructor left the port, pbuf and UDP pcb members uninitialized until begin() was called. Initialize them in the member initializer list, in declaration order. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Haiku 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes eight bugs found during a review of the STM32Ethernet sources. Each fix is a separate commit.
acceptedflag (nowbool, set tofalse).mem_malloc()failure, close only the new pcb withtcp_close()instead of callingtcp_connection_close()with a NULL client.stm32_eth_scheduler()remains the wrapper for the newer timer path._owns_tcp_clientto avoid a double free for clients created from a server-owned structure.stop()whenigmp_joingroup()fails, so the UDP pcb is not leaked.stm32_new_data()fails.The doc-comment cleanup, Doxygen fixes and astyle formatting are already on
main, so they are not part of this PR.Validation
Doxyfile: 0 warnings.