Skip to content

Commit defa4e5

Browse files
committed
fix(android): clamp imported socksPort to non-privileged range 1024-65535
Android (Unix) reserves ports 1-1023 as privileged: a regular app cannot bind to them without root. The previous coerceIn(1, 65535) still allowed privileged ports through, which would fail at bind time on non-rooted devices. Tighten the clamp to coerceIn(1024, 65535). Update the test to cover three boundary cases: above 65535 -> 65535, below 1024 -> 1024, and a privileged port (80) -> 1024.
1 parent fd42b2f commit defa4e5

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

android/app/src/main/java/com/gooserelay/gooserelayvpn/ui/profiles/ProfilesViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ProfilesViewModel @Inject constructor(
175175
val name = root.get("name")?.asString ?: defaultName ?: "Imported"
176176
val debugTiming = root.get("debug_timing")?.asBoolean ?: false
177177
val socksHost = root.get("socks_host")?.asString ?: "127.0.0.1"
178-
val socksPort = root.get("socks_port")?.asInt?.coerceIn(1, 65535) ?: 1080
178+
val socksPort = root.get("socks_port")?.asInt?.coerceIn(1024, 65535) ?: 1080
179179
val socksUser = root.get("socks_user")?.asString ?: ""
180180
val socksPass = root.get("socks_pass")?.asString ?: ""
181181
val googleHost = root.get("google_host")?.asString ?: "216.239.38.120"

android/app/src/test/java/com/gooserelay/gooserelayvpn/ProfilesViewModelParseTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ class ProfilesViewModelParseTest {
4848
}
4949

5050
@Test
51-
fun `clamps socksPort to 1_65535 range`() {
51+
fun `clamps socksPort to 1024_65535 range`() {
5252
val tooHigh = """{"tunnel_key":"k","socks_port":99999}"""
53-
assertThat(vm().parseProfileFromJson(tooHigh)!!.socksPort).isEqualTo(1080)
53+
assertThat(vm().parseProfileFromJson(tooHigh)!!.socksPort).isEqualTo(65535)
5454

5555
val tooLow = """{"tunnel_key":"k","socks_port":0}"""
56-
assertThat(vm().parseProfileFromJson(tooLow)!!.socksPort).isEqualTo(1080)
56+
assertThat(vm().parseProfileFromJson(tooLow)!!.socksPort).isEqualTo(1024)
57+
58+
val privileged = """{"tunnel_key":"k","socks_port":80}"""
59+
assertThat(vm().parseProfileFromJson(privileged)!!.socksPort).isEqualTo(1024)
5760
}
5861

5962
@Test

0 commit comments

Comments
 (0)