Skip to content

Commit

Permalink
Update the buffer's index in DoReceive() any time the buffer's index …
Browse files Browse the repository at this point in the history
…is updated in DoPacket(). Fixes #621
  • Loading branch information
falemagn committed Nov 22, 2023
1 parent b7aaabc commit 205cec1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7456,7 +7456,7 @@ static int DoChannelExtendedData(WOLFSSH* ssh,
}


static int DoPacket(WOLFSSH* ssh)
static int DoPacket(WOLFSSH* ssh, byte* bufferConsumed)
{
byte* buf = (byte*)ssh->inputBuffer.buffer;
word32 idx = ssh->inputBuffer.idx;
Expand All @@ -7469,6 +7469,8 @@ static int DoPacket(WOLFSSH* ssh)

WLOG(WS_LOG_DEBUG, "DoPacket sequence number: %d", ssh->peerSeq);

*bufferConsumed = 0;

idx += UINT32_SZ;
padSz = buf[idx++];

Expand Down Expand Up @@ -7696,6 +7698,7 @@ static int DoPacket(WOLFSSH* ssh)
idx += padSz;
ssh->inputBuffer.idx = idx;
ssh->peerSeq++;
*bufferConsumed = 1;

return ret;
}
Expand Down Expand Up @@ -8084,6 +8087,7 @@ int DoReceive(WOLFSSH* ssh)
byte peerBlockSz = ssh->peerBlockSz;
byte peerMacSz = ssh->peerMacSz;
byte aeadMode = ssh->peerAeadMode;
byte bufferConsumed = 0;

switch (ssh->processReplyState) {
case PROCESS_INIT:
Expand Down Expand Up @@ -8190,25 +8194,29 @@ int DoReceive(WOLFSSH* ssh)
NO_BREAK;

case PROCESS_PACKET:
ret = DoPacket(ssh);
ret = DoPacket(ssh, &bufferConsumed);
ssh->error = ret;
if (ret < 0 && !(ret == WS_CHAN_RXD || ret == WS_EXTDATA ||
ret == WS_CHANNEL_CLOSED || ret == WS_WANT_WRITE ||
ret == WS_REKEYING || ret == WS_WANT_READ)) {
return WS_FATAL_ERROR;
ret = WS_FATAL_ERROR;
}
WLOG(WS_LOG_DEBUG, "PR3: peerMacSz = %u", peerMacSz);
ssh->inputBuffer.idx += peerMacSz;
break;

default:
WLOG(WS_LOG_DEBUG, "Bad process input state, program error");
ssh->error = WS_INPUT_CASE_E;
return WS_FATAL_ERROR;
}
WLOG(WS_LOG_DEBUG, "PR4: Shrinking input buffer");
ShrinkBuffer(&ssh->inputBuffer, 1);
ssh->processReplyState = PROCESS_INIT;

if (bufferConsumed) {
WLOG(WS_LOG_DEBUG, "PR3: peerMacSz = %u", peerMacSz);
ssh->inputBuffer.idx += peerMacSz;

WLOG(WS_LOG_DEBUG, "PR4: Shrinking input buffer");
ShrinkBuffer(&ssh->inputBuffer, 1);
ssh->processReplyState = PROCESS_INIT;
}

WLOG(WS_LOG_DEBUG, "PR5: txCount = %u, rxCount = %u",
ssh->txCount, ssh->rxCount);
Expand Down

0 comments on commit 205cec1

Please sign in to comment.