Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MainActivity : ComponentActivity() {
encryptionMethod = values["DATA_ENCRYPTION_METHOD"]?.toIntOrNull() ?: 1,
encryptionKey = parsedKey,
protocolType = normalizeProtocol(values["PROTOCOL_TYPE"]),
listenPort = values["LISTEN_PORT"]?.toIntOrNull()?.coerceIn(1, 65535) ?: 18000,
listenPort = values["LISTEN_PORT"]?.toIntOrNull()?.coerceIn(1025, 65535) ?: 18000,
resolverBalancingStrategy = values["RESOLVER_BALANCING_STRATEGY"]?.toIntOrNull() ?: 2,
packetDuplicationCount = values["PACKET_DUPLICATION_COUNT"]?.toIntOrNull() ?: 2,
setupPacketDuplicationCount = values["SETUP_PACKET_DUPLICATION_COUNT"]?.toIntOrNull() ?: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ private fun parseProfileTomlForImport(fileName: String, tomlContent: String): Im
encryptionMethod = values["DATA_ENCRYPTION_METHOD"]?.toIntOrNull() ?: 1,
encryptionKey = parsedKey,
protocolType = normalizeProtocol(values["PROTOCOL_TYPE"]),
listenPort = values["LISTEN_PORT"]?.toIntOrNull()?.coerceIn(1, 65535) ?: 18000,
listenPort = values["LISTEN_PORT"]?.toIntOrNull()?.coerceIn(1025, 65535) ?: 18000,
resolverBalancingStrategy = values["RESOLVER_BALANCING_STRATEGY"]?.toIntOrNull() ?: 2,
packetDuplicationCount = values["PACKET_DUPLICATION_COUNT"]?.toIntOrNull() ?: 2,
setupPacketDuplicationCount = values["SETUP_PACKET_DUPLICATION_COUNT"]?.toIntOrNull() ?: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SettingsViewModel @Inject constructor(
encryptionKey = values["ENCRYPTION_KEY"] ?: profile.encryptionKey,
protocolType = normalizeProtocol(values["PROTOCOL_TYPE"], profile.protocolType),
listenPort = values["LISTEN_PORT"]?.toIntOrNull()
?.coerceIn(1, 65535) ?: profile.listenPort,
?.coerceIn(1025, 65535) ?: profile.listenPort,
resolverBalancingStrategy = normalizeResolverBalancingStrategy(
values["RESOLVER_BALANCING_STRATEGY"],
profile.resolverBalancingStrategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ object GlobalSettingsStore {
prefs[KEY_CUSTOM_DNS_SERVERS] = settings.customDnsServers
prefs[KEY_FAKE_DNS_ENABLED] = settings.fakeDnsEnabled
prefs[KEY_INTERNET_SHARING_ENABLED] = settings.internetSharingEnabled
prefs[KEY_INTERNET_SHARING_SOCKS_PORT] = settings.internetSharingSocksPort.coerceIn(1, 65535)
prefs[KEY_INTERNET_SHARING_HTTP_PORT] = settings.internetSharingHttpPort.coerceIn(1, 65535)
prefs[KEY_INTERNET_SHARING_SOCKS_PORT] = settings.internetSharingSocksPort.coerceIn(1025, 65535)
prefs[KEY_INTERNET_SHARING_HTTP_PORT] = settings.internetSharingHttpPort.coerceIn(1025, 65535)
prefs[KEY_INTERNET_SHARING_USER] = settings.internetSharingUser
prefs[KEY_INTERNET_SHARING_PASS] = settings.internetSharingPass
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.masterdns.vpn.util

import org.junit.Assert.assertEquals
import org.junit.Test

class GlobalSettingsPortRangeTest {
@Test
fun clampsBelow1025UpToFloor() {
val settings = GlobalSettings(internetSharingSocksPort = 80, internetSharingHttpPort = 443)
val socks = settings.internetSharingSocksPort.coerceIn(1025, 65535)
val http = settings.internetSharingHttpPort.coerceIn(1025, 65535)
assertEquals(1025, socks)
assertEquals(1025, http)
}

@Test
fun clampsAbove65535DownToCeiling() {
val settings = GlobalSettings(internetSharingSocksPort = 99999)
val socks = settings.internetSharingSocksPort.coerceIn(1025, 65535)
assertEquals(65535, socks)
}

@Test
fun preservesValidPort() {
val settings = GlobalSettings(internetSharingSocksPort = 8090, internetSharingHttpPort = 18000)
assertEquals(8090, settings.internetSharingSocksPort.coerceIn(1025, 65535))
assertEquals(18000, settings.internetSharingHttpPort.coerceIn(1025, 65535))
}
}
Loading