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 codeql alerts #9647

Merged

Conversation

ganeshkumarsv
Copy link
Contributor

@ganeshkumarsv ganeshkumarsv commented Oct 25, 2021

What does this PR do?

This PR fixes some of the code scanning alerts.
You can find the PR conversation we had with Agent Core team here: https://github.com/stephengroat/datadog-agent/pull/1/files

This PR fixes the following alerts
https://github.com/DataDog/datadog-agent/pull/9647/checks?check_run_id=4000934041
Feel free to let me know if this PR should be split into multiple small PRs

Motivation

What inspired you to submit this pull request?
Github Code Scanning

Additional Notes

Anything else we should know when reviewing?

Describe how to test your changes

Write here in detail how you have tested your changes
and instructions on how this should be tested in QA.

Describe or link instructions to set up environment
for testing, if the process requires more than just
running the agent on one of the supported platforms.

Checklist

  • A release note has been added or the changelog/no-changelog label has been applied.
  • The need-change/operator and need-change/helm labels has been applied if applicable.
  • The appropriate team/.. label has been applied, if known.
  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • The config template has been updated if applicable.

Note: Adding GitHub labels is only possible for contributors with write access.

Copy link
Contributor

@djmitche djmitche left a comment

Choose a reason for hiding this comment

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

Changes look good. I think the only thing left is the HTTP responses?

@mx-psi mx-psi added this to the 7.33.0 milestone Oct 28, 2021
@mx-psi mx-psi added changelog/no-changelog [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. labels Oct 28, 2021
@mx-psi
Copy link
Member

mx-psi commented Oct 28, 2021

@stephengroat-dd you need to sign the CLA for this to be mergeable

@ganeshkumarsv
Copy link
Contributor Author

@mx-psi Thanks for letting us know. All committers have signed the CLA now :)

@mx-psi
Copy link
Member

mx-psi commented Oct 29, 2021

FYI: I pushed a copy of this branch to mx-psi/test-SECSYS-160-fix-codeql-alerts so that we run a full Gitlab pipeline (you can see it in the status check section since the commits are the same)

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

CI looks good and changes on Agent Platform files look good too

Comment on lines +87 to +89
// Before Go 1.17, we can use the following trick to define MaxInt
const MaxInt = ^uint(0) >> 1
if err != nil || titleLength < 0 || titleLength > int64(MaxInt) {
Copy link
Member

Choose a reason for hiding this comment

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

As titleLength is an int64, there is no possible value that can be greater than MaxInt.
So, titleLength > int64(MaxInt) is an antilogy, isn’t it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

On 64-bit machines (including that used for the playground), you are correct. In a 32-bit context, int is the same as int32, so there are lots of int64 values that are greater than MaxInt.

This is one of those holdovers in Go from the C/C++ world that has caused lots of bugs in C/C++ and continues to do so in Go.

Copy link
Contributor

Choose a reason for hiding this comment

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

parseInt64 is only used in this function. So I think we can change parseInt64() int64 to parseUint() uint (adjusting implementation accordingly) and avoid the need for range checks here. WDYT?

@vickenty vickenty added the [deprecated] qa/skip-qa - use other qa/ labels [DEPRECATED] Please use qa/done or qa/no-code-change to skip creating a QA card label Nov 5, 2021
Copy link
Member

@AlexandreYang AlexandreYang left a comment

Choose a reason for hiding this comment

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

lgmt for snmp related changes

@djmitche
Copy link
Contributor

I pinged some slack channels for the remaining two teams. It'd be great to get this merged for 7.33.0, so before Friday.

@djmitche djmitche added the team/agent-apm trace-agent label Nov 12, 2021
@djmitche
Copy link
Contributor

The APM-related changes (pkg/trace) look fine to me, but I don't know where the skeletons are buried in that package. So, I've added the APM team to the QA list (by adding a label), and they can have a look and test it out in the QA process.

@djmitche djmitche merged commit 6a0f6a6 into DataDog:main Nov 12, 2021
zandrewitte pushed a commit to StackVista/stackstate-agent that referenced this pull request Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog [deprecated] qa/skip-qa - use other qa/ labels [DEPRECATED] Please use qa/done or qa/no-code-change to skip creating a QA card [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. team/agent-apm trace-agent
Projects
None yet
Development

Successfully merging this pull request may close these issues.