SSU: Fix NPE handling SSU1 peer test msg 7

Reported by drzed
This commit is contained in:
zzz
2023-01-08 12:19:14 -05:00
parent d9a75a5afc
commit 433340c11b

View File

@@ -259,6 +259,17 @@ class PeerTestManager {
_log.warn("Unable to get our IP", uhe);
return false;
}
} else {
// set Alice IP/port, needed for receiveTestReply() checks for msg 7
RouterAddress ra = _transport.getCurrentExternalAddress(bob.isIPv6());
if (ra != null) {
byte[] ourIP = ra.getIP();
int ourPort = ra.getPort();
try {
InetAddress addr = InetAddress.getByAddress(ourIP);
test.setAlice(addr, ourPort, null);
} catch (UnknownHostException uhe) {}
}
}
_currentTest = test;
_currentTestComplete = false;
@@ -592,8 +603,24 @@ class PeerTestManager {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Receive test reply from Charlie: " + test);
boolean portok = testPort == test.getAlicePort();
boolean IPok = DataHelper.eq(ip, test.getAliceIP().getAddress());
// fixups if we didn't know our IP/port at the start
int origPort = test.getAlicePort();
InetAddress origAddr = test.getAliceIP();
boolean portok;
if (origPort > 0) {
portok = testPort == origPort;
} else {
portok = true;
test.setAlice(test.getAliceIP(), testPort, null);
}
boolean IPok;
if (origAddr != null) {
IPok = DataHelper.eq(ip, origAddr.getAddress());
} else {
IPok = true;
test.setAlice(addr, test.getAlicePort(), null);
}
if (!portok || !IPok) {
if (_log.shouldWarn())
_log.warn("Charlie said we had a different IP/port: " +