Skip to content

Commit 18b9249

Browse files
ejohnstownphilljj
authored andcommitted
Make the disconnect tests prove what they claim
The two disconnect tests ran on a session that had never finished user auth, so IsMessageAllowed() blocked the sends on its own and the "nothing on the wire" assertions held even with the gates removed. Both now sit past user auth. With only the shutdown gate reverted the test measures 72 bytes out and both teardown flags set, where before it measured nothing. - wolfSSH_stream_peek() reports WS_DISCONNECT when the channel is gone, the way wolfSSH_stream_read() already did; a missing channel used to read as a bad argument on a session that had simply ended - the drain test covers the no-channel case for both calls Issue: F-8837
1 parent 5805256 commit 18b9249

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/ssh.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,17 @@ int wolfSSH_stream_peek(WOLFSSH* ssh, byte* buf, word32 bufSz)
12451245

12461246
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_stream_peek()");
12471247

1248-
if (ssh == NULL || ssh->channelList == NULL)
1248+
if (ssh == NULL)
1249+
return WS_BAD_ARGUMENT;
1250+
1251+
if (ssh->channelList == NULL) {
1252+
/* No channel left to drain, so the disconnect is all there is. */
1253+
if (ssh->disconnected) {
1254+
ssh->error = WS_DISCONNECT;
1255+
return WS_FATAL_ERROR;
1256+
}
12491257
return WS_BAD_ARGUMENT;
1258+
}
12501259

12511260
if (ssh->isKeying) {
12521261
ssh->error = WS_REKEYING;

tests/regress.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,20 @@ static void TestDisconnectDrainsBufferedData(void)
30233023
AssertIntEQ(ret, WS_FATAL_ERROR);
30243024
AssertIntEQ(wolfSSH_get_error(ssh), WS_DISCONNECT);
30253025

3026+
/* With the channel gone there is no buffer left to drain, so both
3027+
* report the disconnect rather than a bad argument. */
3028+
AssertIntEQ(ChannelRemove(ssh, ssh->channelList->channel,
3029+
WS_CHANNEL_ID_SELF), WS_SUCCESS);
3030+
AssertNull(ssh->channelList);
3031+
3032+
ret = wolfSSH_stream_peek(ssh, NULL, 1);
3033+
AssertIntEQ(ret, WS_FATAL_ERROR);
3034+
AssertIntEQ(wolfSSH_get_error(ssh), WS_DISCONNECT);
3035+
3036+
ret = wolfSSH_stream_read(ssh, data, sizeof(data));
3037+
AssertIntEQ(ret, WS_FATAL_ERROR);
3038+
AssertIntEQ(wolfSSH_get_error(ssh), WS_DISCONNECT);
3039+
30263040
wolfSSH_free(ssh);
30273041
wolfSSH_CTX_free(ctx);
30283042
}
@@ -3052,6 +3066,9 @@ static void TestDisconnectBlocksEverySend(void)
30523066
AssertNotNull(ssh);
30533067
AddSessionChannel(ssh);
30543068
channelId = ssh->channelList->channel;
3069+
/* Past userauth, or the message filter blocks the sends on its own and
3070+
* the wire check below proves nothing. */
3071+
ssh->connectState = CONNECT_SERVER_USERAUTH_ACCEPT_DONE;
30553072

30563073
MemIoInit(&io, NULL, 0, out, sizeof(out));
30573074
wolfSSH_SetIOReadCtx(ssh, &io);
@@ -3379,6 +3396,9 @@ static void TestShutdownQuietAfterDisconnect(void)
33793396
AssertNotNull(ssh);
33803397
AddSessionChannel(ssh);
33813398
channel = ssh->channelList;
3399+
/* Past userauth, or the message filter blocks the teardown on its own
3400+
* and the wire check below proves nothing. */
3401+
ssh->connectState = CONNECT_SERVER_USERAUTH_ACCEPT_DONE;
33823402

33833403
inSz = BuildDisconnectPacket(WOLFSSH_DISCONNECT_BY_APPLICATION,
33843404
in, sizeof(in));

0 commit comments

Comments
 (0)