소스 검색

config: fix wrong Peer endpoint string format

When a tunnel is running, saving the tunnel's config with an IPv6
address endpoint like [::1]:42 would result in the wrong format :42.
This patch fixes it.

For endpoints with an IPv6 address(e.g. [::1]:42). Since the default
endpoint InetSocketAddress is created unresolved, getEndpointString()
returns "[::1]:42" (InetSocketAddress.getHostString() returns the
literal hostname). After the endpoint is resolved, getEndpointString()
returns ":42" (InetSocketAddress.getHostString() returns the IPv6
address without the square brackets). This inconsistent return values
caused the above mentioned bug.

With this patch, function getEndpointString would return the right
format string whether the endpoint is resolved or not.

Signed-off-by: Zhao Gang <gang.zhao.42@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
master
Zhao Gang 6 년 전
committed by Jason A. Donenfeld
부모
커밋
61d4f17f5d
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. +4
    -1
      app/src/main/java/com/wireguard/config/Peer.java

+ 4
- 1
app/src/main/java/com/wireguard/config/Peer.java 파일 보기

@@ -71,7 +71,10 @@ public class Peer {
private String getEndpointString() {
if (endpoint == null)
return null;
return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort());
if (endpoint.getHostString().contains(":") && !endpoint.getHostString().contains("["))
return String.format("[%s]:%d", endpoint.getHostString(), endpoint.getPort());
else
return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort());
}

public int getPersistentKeepalive() {


불러오는 중...
취소
저장