sys/net/grnc/netreg: avoid creating an infinite loop #19238
Merged
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.
Contribution description
If a socket is registered twice, it's
next
pointer will point to itself, creating an infinite loop in_netreg_lookup()
when a packet is received.Especially when this only happens sporadically (code path that would normally close the socket is not taken) it creates a very hard to debug issue where the system is just locked up.
Instead, fail early and loud.
This would be an infinite loop on RX before, now it's a crash right at the place where the error condition occurs.
Testing procedure
Call
gnrc_sock_create()
on the same socket twice.On
master
this will not fail, but as soon as you receive a packet on the socket, the system locks up in an infinite loop.With this patch, the assertion will trigger on the 2nd call to
gnrc_sock_create()
.Issues/PRs references