Skip to content

common: validate endpoint fields in parseEndpoint#586

Open
wenzaee wants to merge 1 commit intokubeedge:mainfrom
wenzaee:fix-parse-endpoint-validation
Open

common: validate endpoint fields in parseEndpoint#586
wenzaee wants to merge 1 commit intokubeedge:mainfrom
wenzaee:fix-parse-endpoint-validation

Conversation

@wenzaee
Copy link
Copy Markdown

@wenzaee wenzaee commented Apr 10, 2026

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PR implements the TODO in parseEndpoint by adding IP and port validation.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
NONE


@kubeedge-bot kubeedge-bot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 10, 2026
@kubeedge-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wenzaee
To complete the pull request process, please assign fisherxu after the PR has been reviewed.
You can assign the PR to them by writing /assign @fisherxu in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot
Copy link
Copy Markdown
Collaborator

Welcome @wenzaee! It looks like this is your first PR to kubeedge/edgemesh 🎉

@kubeedge-bot kubeedge-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 10, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements IP and port validation in the parseEndpoint function within pkg/loadbalancer/util.go, replacing a previous TODO. The review feedback suggests refining the validation logic by incorporating a port range check and removing redundant checks, while also highlighting that the current implementation is limited to IPv4 support.

Comment thread pkg/loadbalancer/util.go
Comment on lines +35 to +41
port, err := strconv.Atoi(info[portIndex])
if err != nil {
return "", "", "", "", false
}
if net.ParseIP(info[ipIndex]) == nil || !isValidEndpoint(info[ipIndex], port) {
return "", "", "", "", false
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The validation logic can be improved by checking the full valid port range (1-65535) and removing redundant checks. Since net.ParseIP already validates that the string is a valid IP address, the host != "" check inside isValidEndpoint is unnecessary here. Combining the port conversion and range check also makes the code more concise.

Additionally, note that the current parsing logic using strings.Split(endpoint, ":") is incompatible with IPv6 addresses as they contain colons. While fixing the parsing logic might be out of scope for this PR, it's worth noting that this function currently only supports IPv4.

Suggested change
port, err := strconv.Atoi(info[portIndex])
if err != nil {
return "", "", "", "", false
}
if net.ParseIP(info[ipIndex]) == nil || !isValidEndpoint(info[ipIndex], port) {
return "", "", "", "", false
}
port, err := strconv.Atoi(info[portIndex])
if err != nil || port <= 0 || port > 65535 {
return "", "", "", "", false
}
if net.ParseIP(info[ipIndex]) == nil {
return "", "", "", "", false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants