Fixes #11634 Add support for IP segments above 127 in Socks5Proxy (#11636)

Now properly parsing IP bytes (0..255) without clashing with Java bytes (-128..127).
This commit is contained in:
Marcin Kozak 2024-04-18 12:02:12 +02:00 committed by GitHub
parent 6566a1c6f6
commit cc5f18bd11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -270,7 +270,7 @@ public class Socks5Proxy extends Proxy
.put(Socks5.ADDRESS_TYPE_IPV4); .put(Socks5.ADDRESS_TYPE_IPV4);
for (int i = 1; i <= 4; ++i) for (int i = 1; i <= 4; ++i)
{ {
byteBuffer.put(Byte.parseByte(matcher.group(i))); byteBuffer.put((byte)Integer.parseInt(matcher.group(i)));
} }
byteBuffer.putShort(port) byteBuffer.putShort(port)
.flip(); .flip();

View File

@ -86,7 +86,7 @@ public class Socks5ProxyTest
byte ip1 = 127; byte ip1 = 127;
byte ip2 = 0; byte ip2 = 0;
byte ip3 = 0; byte ip3 = 0;
byte ip4 = 13; short ip4 = 255;
String serverHost = ip1 + "." + ip2 + "." + ip3 + "." + ip4; String serverHost = ip1 + "." + ip2 + "." + ip3 + "." + ip4;
int serverPort = proxyPort + 1; // Any port will do int serverPort = proxyPort + 1; // Any port will do
String method = "GET"; String method = "GET";
@ -129,7 +129,7 @@ public class Socks5ProxyTest
assertEquals(ip1, buffer.get()); assertEquals(ip1, buffer.get());
assertEquals(ip2, buffer.get()); assertEquals(ip2, buffer.get());
assertEquals(ip3, buffer.get()); assertEquals(ip3, buffer.get());
assertEquals(ip4, buffer.get()); assertEquals((byte)ip4, buffer.get());
assertEquals(serverPort, buffer.getShort() & 0xFFFF); assertEquals(serverPort, buffer.getShort() & 0xFFFF);
// Write connect response. // Write connect response.