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 MDNS crash on S2 #6193

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Changes from all commits
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
5 changes: 5 additions & 0 deletions ports/espressif/common-hal/mdns/Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ mp_obj_t common_hal_mdns_server_find(mdns_server_obj_t *self, const char *servic
next = next->next;
}
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_results, NULL));
// The empty tuple object is shared and stored in flash so return early if
Copy link
Member

Choose a reason for hiding this comment

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

mp_obj_new_tuple already sets the length to n, so instead of special casing num_results == 0, you can remove the assignment of len below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I set it to added below in case we can make the wrapper objects for all of the results. So, it may be different than the value at alloc time. Want me to make it compare the current len vs added and then set it if different?

Copy link
Member

Choose a reason for hiding this comment

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

urp .. tuples are meant to be static in size, I'm not sure of the impact of truncating one after initial allocation. but the tuple at this point is not seen by python code, so it doesn't matter.

// we got it. Without this we'll crash when trying to set len below.
if (num_results == 0) {
return MP_OBJ_FROM_PTR(tuple);
}
next = results;
// Don't error if we're out of memory. Instead, truncate the tuple.
uint8_t added = 0;
Expand Down