Skip to content

Fix code scanning alert no. 50: Size computation for allocation may overflow #1088

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

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

esimkowitz
Copy link
Member

Fixes https://github.com/wavetermdev/waveterm/security/code-scanning/50

To fix the problem, we need to ensure that the size computation for the allocation does not overflow. This can be achieved by validating the length of barr before performing the arithmetic operation. We will set a maximum allowable size for barr to ensure that the sum of oscPrefixLen(oscNum) and len(barr) does not exceed the maximum value for an int.

  1. Define a maximum allowable size for barr (e.g., 64 MB).
  2. Check the length of barr against this maximum size before performing the allocation.
  3. If barr exceeds the maximum size, return an error.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

esimkowitz and others added 2 commits October 21, 2024 12:06
…verflow

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@esimkowitz esimkowitz marked this pull request as ready for review October 21, 2024 19:15
@esimkowitz esimkowitz merged commit 1fc6dd7 into main Oct 21, 2024
5 of 6 checks passed
@esimkowitz esimkowitz deleted the alert-autofix-50 branch October 21, 2024 21:05
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
…verflow (wavetermdev#1088)

Fixes
[https://github.com/wavetermdev/waveterm/security/code-scanning/50](https://github.com/wavetermdev/waveterm/security/code-scanning/50)

To fix the problem, we need to ensure that the size computation for the
allocation does not overflow. This can be achieved by validating the
length of `barr` before performing the arithmetic operation. We will set
a maximum allowable size for `barr` to ensure that the sum of
`oscPrefixLen(oscNum)` and `len(barr)` does not exceed the maximum value
for an `int`.

1. Define a maximum allowable size for `barr` (e.g., 64 MB).
2. Check the length of `barr` against this maximum size before
performing the allocation.
3. If `barr` exceeds the maximum size, return an error.


_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant