Skip to content

Commit 1ea1331

Browse files
oyydjuanarbol
authored andcommitted
quic: client should work when receives invalid preferred address
If we set `preferredAddressPolicy` to `accept` on `QuicClientSession` but receives an invalid preferred address, e.g. we don't define `preferredAddress` on the server, the `QuicClientSession` should still work. Before this PR, the included test will cause segmetation fault. PR-URL: nodejs#155 Reviewed-By: James M Snell <[email protected]>
1 parent 08f721e commit 1ea1331

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/node_quic_session.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,11 @@ bool QuicClientSession::SendConnectionClose() {
28012801
sendbuf_.Cancel();
28022802
QuicError error = GetLastError();
28032803

2804-
if (!WritePackets("client connection close - write packets"))
2804+
// If we're not already in the closing period,
2805+
// first attempt to write any pending packets, then
2806+
// start the closing period.
2807+
if (!IsInClosingPeriod() &&
2808+
!WritePackets("client connection close - write packets"))
28052809
return false;
28062810

28072811
ssize_t nwrite =
@@ -3223,8 +3227,8 @@ int QuicSession::OnSelectPreferredAddress(
32233227
void* user_data) {
32243228
QuicSession* session = static_cast<QuicSession*>(user_data);
32253229
QuicSession::Ngtcp2CallbackScope callback_scope(session);
3226-
return session->SelectPreferredAddress(dest, paddr) ?
3227-
0 : NGTCP2_ERR_CALLBACK_FAILURE;
3230+
session->SelectPreferredAddress(dest, paddr);
3231+
return 0;
32283232
}
32293233

32303234
// Called by ngtcp2 when a stream has been closed for any reason.

src/node_quic_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class SocketAddress {
200200
}
201201

202202
char host[NI_MAXHOST];
203-
if (uv_inet_ntop(af, binaddr, host, sizeof(host)) == 0)
203+
if (uv_inet_ntop(af, binaddr, host, sizeof(host)) != 0)
204204
return false;
205205

206206
addrinfo hints{};

0 commit comments

Comments
 (0)