Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lwip): Add early out in NetworkUDP::parsePacket() when socket has no data #10075

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libraries/Network/src/NetworkUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ int NetworkUDP::parsePacket() {
struct sockaddr_storage si_other_storage; // enough storage for v4 and v6
socklen_t slen = sizeof(sockaddr_storage);
int len;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here len should be set to 0, else it might not be initialized and might not be 0 for the next check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I've clearly spent too much time in C# lately, where "out" variables are guaranteed to be assigned 😂

if (ioctl(udp_server, FIONREAD, &len) == -1) {
log_e("could not check for data in buffer length: %d", errno);
return 0;
}
if (!len) {
return 0;
}
char *buf = (char *)malloc(1460);
if (!buf) {
return 0;
Expand Down