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

treewide: Fix problems identified by CodeQL #17516

Merged
merged 5 commits into from
Oct 11, 2021
Merged

treewide: Fix problems identified by CodeQL #17516

merged 5 commits into from
Oct 11, 2021

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented Oct 1, 2021

This PR fixes a number of problems identified by CodeQL.

See individual commits for details.

@twpayne twpayne added the release-note/misc This PR makes changes that have no direct user impact. label Oct 1, 2021
@twpayne twpayne requested review from a team as code owners October 1, 2021 16:13
@twpayne twpayne requested a review from a team October 1, 2021 16:13
@twpayne twpayne requested a review from a team as a code owner October 1, 2021 16:13
@twpayne
Copy link
Contributor Author

twpayne commented Oct 1, 2021

/test

Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes! Couple of minor questions below.

pkg/identity/numericidentity.go Outdated Show resolved Hide resolved
} else if lenUint64 > math.MaxInt64 {
return block.Bytes(), 0, 0, fmt.Errorf("block length overflow")
Copy link
Member

Choose a reason for hiding this comment

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

Couple of questions here:

  • Why compare a uint64 type against an int64 size? Is there code lower down that is limiting this to the positive 63-bit range or signed integer comparisons below?
  • Why is this a problem if ParseUint(..., 64) is limiting it to 64 bits? I understand that the result is a uint which doesn't have a defined size, but presumably the last parameter to ParseUint() should bound that within 64 bits.

The more I look at this particular change, the more I wonder if the complaint is less about the 64-bit size up here but more to do with some comparison against a shorter type below 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why compare a uint64 type against an int64 size?

We parse a value using strconv.ParseUint (which returns a uint64) but we store the value in blockLen (which is an int), so any value greater that math.MaxInt64 will overflow the int (assuming a 64 bit platform).

The more I look at this particular change, the more I wonder if the complaint is less about the 64-bit size up here but more to do with some comparison against a shorter type below 🤔

It's possible. We only run CodeQL against master and it can be difficult to trace exactly why CodeQL complains, so it's possible that this change won't fix CodeQL's complaints.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right. If two lines down we're casting down to int(...) then seems like we should be doing a math.MaxInt() here instead?

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. Note that math.MaxInt isn't available at the moment as our runtime CI VMs are still running Go 1.16, but I've left a FIXME to switch this to math.MaxInt in the code for when we get them upgraded.

In the short term, I've used the max int64 constant, which is not correct if Cilium is compiled for a 32-bit architecture, but switching to math.MaxInt later will fix this.

@twpayne
Copy link
Contributor Author

twpayne commented Oct 4, 2021

/test

@twpayne
Copy link
Contributor Author

twpayne commented Oct 4, 2021

test-runtime failed because the CI runtime VMs are still running Go 1.16 (waiting for #17394). I've added a workaround.

@twpayne
Copy link
Contributor Author

twpayne commented Oct 4, 2021

/ci-multicluster

@twpayne
Copy link
Contributor Author

twpayne commented Oct 4, 2021

/test-gke

@twpayne
Copy link
Contributor Author

twpayne commented Oct 4, 2021

/test-runtime

@twpayne
Copy link
Contributor Author

twpayne commented Oct 5, 2021

/test

@twpayne
Copy link
Contributor Author

twpayne commented Oct 6, 2021

/test

CodeQL identified "Incorrect conversion of a 64-bit integer from  to a
lower bit size type uint16 without an upper bound check".

Signed-off-by: Tom Payne <tom@isovalent.com>
CodeQL identified multiple "Incorrect conversion of a 64-bit integer
from  to a lower bit size type uint32 without an upper bound check.".

Signed-off-by: Tom Payne <tom@isovalent.com>
CodeQL identified "Incorrect conversion of a 64-bit integer from  to a
lower bit size type int without an upper bound check."

Signed-off-by: Tom Payne <tom@isovalent.com>
CodeQL identified "Incorrect conversion of a 64-bit integer from  to a
lower bit size type int without an upper bound check."

Signed-off-by: Tom Payne <tom@isovalent.com>
CodeQL identified "This regular expression has an unescaped dot before
'com', so it might match more hosts than expected when used ."

Signed-off-by: Tom Payne <tom@isovalent.com>
@twpayne
Copy link
Contributor Author

twpayne commented Oct 8, 2021

/test

2 similar comments
@twpayne
Copy link
Contributor Author

twpayne commented Oct 8, 2021

/test

@twpayne
Copy link
Contributor Author

twpayne commented Oct 8, 2021

/test

@twpayne
Copy link
Contributor Author

twpayne commented Oct 11, 2021

CI is mostly green, marking as ready-to-merge.

@twpayne twpayne added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Oct 11, 2021
@errordeveloper errordeveloper merged commit 6a722d3 into cilium:master Oct 11, 2021
@aditighag aditighag removed their assignment Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants