-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add guard against invalid port numbers passed into NetCopyConnectionInfo #4380
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Must be 1..65535
it[7].toInt() | ||
} else { | ||
LOGGER.warn("Port number is out of range: ${it[7]}") | ||
0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this return the default port for ssh? I would think that returning 0 would just crash whatever uses this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this to be the responsibility of downstream code - here is for just the regex extraction magic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. The type looks like it doesn't have any error state. port: Int
should probably be port: Int?
and be set to null on these cases, so that users know that the port could be "broken/unset".
} | ||
} catch (e: NumberFormatException) { | ||
LOGGER.warn("Unable to parse port number: ${it[7]}", e) | ||
0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. It should be downstream code's responsibility of determining the default port number of different protocols.
Description
Add guard against invalid Integers as port number passed into NetCopyConnectionInfo.
Issue tracker
Fixes #4362
Automatic tests
Manual tests
Build tasks success
Successfully running following tasks on local:
./gradlew assembledebug
./gradlew spotlessCheck