Fixed undefined behavior in netmask generation #1717#1718
Closed
rfrohl wants to merge 1 commit intonmap:masterfrom
Closed
Fixed undefined behavior in netmask generation #1717#1718rfrohl wants to merge 1 commit intonmap:masterfrom
rfrohl wants to merge 1 commit intonmap:masterfrom
Conversation
nnposter
reviewed
Aug 31, 2019
| } | ||
| else { | ||
| mask[i] = ~((1 << (unmasked_bits - (32 * (4 - i)))) - 1); | ||
| mask[i] = ~(0xffffffff % (1 << unmasked_bits)); |
There was a problem hiding this comment.
This code suffers from a similar issue as the original one: There is no guaranteed outcome when unmasked_bits exceeds 31. As an example:
#include <stdio.h>
void main ()
{
int m=32;
printf("%08x\n%08x\n",(0xFFFFFFFF<<(m-1)<<1),(0xFFFFFFFF<<m));
}When compiled with GCC on Ubuntu 18.04 x64:
$ ./a.out
00000000
ffffffff
Author
There was a problem hiding this comment.
I assumed that it would hit another branch if unmasked_bits is a multiple of 32. But I my understanding of how mask is used in the rest of the code is limited, so I might miss something here.
Will test the other patch from the ticket on Monday
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.
Tested this change on x86_64, i586, ppc, ppc64, ppc64le, aarch64 and s390x. Unit tests passed successfully on these architectures.
Also played around with the test binary (addrset) a bit and could not find any obvious problems with the change.