fix: validate recvfrom() return before indexing into buf (AUD-001) - #180
Open
occamsshavingkit wants to merge 1 commit into
Open
fix: validate recvfrom() return before indexing into buf (AUD-001)#180occamsshavingkit wants to merge 1 commit into
occamsshavingkit wants to merge 1 commit into
Conversation
Move the null-termination write (buf[ret] = 0x00) and the corresponding printf() after the ret <= 0 guard, so a negative return from recvfrom() or a full-capacity datagram cannot write out of bounds. Before this fix, ret == DATA_BUF_SIZE wrote one byte past the buffer, and a negative return indexed before it.
niansa
added a commit
to niansa/ioLibrary_Driver
that referenced
this pull request
Jul 29, 2026
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 out-of-bounds write in
loopback_udpc()wherebuf[ret] = 0x00was executed before checking whetherret <= 0.Problem
In
Application/loopback/loopback.c:247-254, the UDP client loopback executed:ret == DATA_BUF_SIZEwrites one byte past the buffer (stack-buffer-overflow under ASan)SOCKERR_SOCKCLOSED = -13) index before the buffer (stack-buffer-underflow)Fix
Move the
ret <= 0check beforebuf[ret] = 0x00andprintf(), preserving both after the guard.Verification
_WIZCHIP_valuesrecvfrom()returningDATA_BUF_SIZE,-13, and0— no sanitizer abort