Skip to content

Commit f5af376

Browse files
committed
Try one more time to fix CodeQL warning
1 parent 7078551 commit f5af376

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎junixsocket-common/src/main/java/org/newsclub/net/unix/AFInetAddress.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ static final byte[] unwrapAddress(InetAddress addr, AFAddressFamily<?> af)
178178
throw new SocketException("Unsupported address");
179179
}
180180

181-
String hostname = addr.getHostName(); // lgtm[java/tainted-numeric-cast] suppress CodeQL warning
182-
return unwrapAddress(hostname, af);
181+
String hostname = addr.getHostName();
182+
try {
183+
return unwrapAddress(hostname, af);
184+
} catch (IllegalStateException | IllegalArgumentException e) {
185+
throw new SocketException("Unsupported address");
186+
}
183187
}
184188

185189
static final byte[] unwrapAddress(String hostname, AFAddressFamily<?> af) throws SocketException {
@@ -214,7 +218,7 @@ static final byte[] unwrapAddress(String hostname, AFAddressFamily<?> af) throws
214218
byte[] unwrapped = new byte[(len - 2) / 2];
215219
for (int i = 2, n = encodedHostname.length(), o = 0; i < n; i += 2, o++) {
216220
int v = Integer.parseInt(encodedHostname.substring(i, i + 2), 16);
217-
unwrapped[o] = (byte) v;
221+
unwrapped[o] = (byte) (v & 0xFF);
218222
}
219223
return unwrapped;
220224
} else {

0 commit comments

Comments
 (0)