Additional check of port number validity

Must be 1..65535
This commit is contained in:
Raymond Lai
2025-04-27 22:46:27 +08:00
parent e91b994e1d
commit c9c597843c
2 changed files with 10 additions and 1 deletions
@@ -110,7 +110,13 @@ class NetCopyConnectionInfo(url: String) {
* this branch must be integer
*/
try {
it[7].toInt()
// Need to make sure port number is in range
if (it[7].toInt() in 1..65535) {
it[7].toInt()
} else {
LOGGER.warn("Port number is out of range: ${it[7]}")
0
}
} catch (e: NumberFormatException) {
LOGGER.warn("Unable to parse port number: ${it[7]}", e)
0
@@ -346,6 +346,9 @@ class NetCopyConnectionInfoTest {
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:21097/a/b/c/d/e").run {
assertEquals(21097, this.port)
}
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:99999/a/b/c/d/e").run {
assertEquals(0, this.port)
}
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1/a/b/c/d/e").run {
assertEquals(0, this.port)
}