Potential fix for code scanning alert no. 1: Incorrect conversion between integer types #5
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.
Potential fix for https://github.com/aka76bm/cli/security/code-scanning/1
To fix this issue, we must check that the input port value falls into the valid range for a port (
0 < port <= 65535) before converting frominttouint16. Ininternal/codespaces/portforwarder/port_forwarder.go, the problematic code is on line 267, whereuint16(remotePort)is called as an argument toDeleteTunnelPort. To address this, introduce a bounds check before the conversion, and only proceed if the port is valid—otherwise, return an error (or fallback as appropriate for the context). The fix should also preferably use a helper function for conversion, similar to theconvertIntToUint16function used elsewhere in the file (see lines 230-233). IfconvertIntToUint16exists, use it instead for consistency.Specifically:
UpdatePortVisibility, add logic to convert and checkremotePortsafely before deleting the port.convertIntToUint16exists and is suitable, reuse it; otherwise, define/import such a helper.math(for MaxUint16), ensure the import exists.Suggested fixes powered by Copilot Autofix. Review carefully before merging.