Skip to content

Fix unsafe integer conversion in UpdatePortVisibility#14

Open
Copilot wants to merge 2 commits intotrunkfrom
copilot/apply-autofixes-16
Open

Fix unsafe integer conversion in UpdatePortVisibility#14
Copilot wants to merge 2 commits intotrunkfrom
copilot/apply-autofixes-16

Conversation

Copy link

Copilot AI commented Feb 14, 2026

Potential fix for alerts


Summary

Replaced unsafe uint16() cast with validated convertIntToUint16() in UpdatePortVisibility to prevent integer overflow when port values exceed valid range (0-65535) or are negative.

Changes

  • Port conversion validation: Added bounds checking before type conversion from int to uint16
  • Error handling: Returns descriptive error if port number is invalid

Before

err = fwd.connection.TunnelManager.DeleteTunnelPort(ctx, fwd.connection.Tunnel, uint16(remotePort), fwd.connection.Options)

After

remotePortUint16, err := convertIntToUint16(remotePort)
if err != nil {
    return fmt.Errorf("error converting remote port: %w", err)
}
err = fwd.connection.TunnelManager.DeleteTunnelPort(ctx, fwd.connection.Tunnel, remotePortUint16, fwd.connection.Options)

This aligns with existing pattern used elsewhere in the file (lines 72, 106, 230).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Continue Tasks: ❌ 1 failed — View all

Co-authored-by: darkangelpraha <183031713+darkangelpraha@users.noreply.github.com>
@darkangelpraha darkangelpraha marked this pull request as ready for review February 14, 2026 04:46
Copilot AI review requested due to automatic review settings February 14, 2026 04:46
Copilot AI changed the title [WIP] Autofix Code Scanning Alert Fix unsafe integer conversion in UpdatePortVisibility Feb 14, 2026
Copilot AI requested a review from darkangelpraha February 14, 2026 04:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a code scanning alert about incorrect conversion between integer types in the port forwarding code. The fix replaces an unsafe direct cast from int to uint16 with a call to the existing convertIntToUint16() helper function, which includes proper range validation and error handling.

Changes:

  • Added safe integer conversion using convertIntToUint16() before calling DeleteTunnelPort() in the UpdatePortVisibility method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants