CNET Chnls: deterministic protocol finding #375
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.
The
initialize_chnl
andcnet_protosw
in thechannel(int, int, int)
function can encounter bugs if the input to thechannel
is wrong.Assume the user input of
type
arg inchannel
is equal to 10002 or the value ofSOCK_CLOEXEC | SOCK_DGRAM
:cnet_protosw_find
will accept the value (even if it is wrong) just because of casting from 4B signed int ofchannel
arguments to 2B unsigned int ofcnet_protosw_find
arguments. The function will return that the desired protocol isSOCK_DGRAM
even if it might not be. Any value that can result in 2 when cast to uint16 will have a correct value even if this is not the desired behavior. A simple mitigation is to prevent casting, especially since higher-level APIs likechannel
useint
notuint_16
.initialize_chnl
also sinks all non-DGRAM and non-ICMP6 channel types as TCP. This can be problematic ifcnet_protosw_find
returns a wrong value. I also think it is neater to check the protocol here and not only assume it will be TCP, for future protocol additions and integrity.The branch also has minor log fixes.