Skip to content

Commit 96f3aa7

Browse files
yosuke-wolfsslejohnstown
authored andcommitted
Fix DoRequestSuccess and DoRequestFailure, Add regress test
1 parent 0479a3a commit 96f3aa7

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

src/internal.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6578,16 +6578,11 @@ static int DoIgnore(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
65786578

65796579
static int DoRequestSuccess(WOLFSSH *ssh, byte *buf, word32 len, word32 *idx)
65806580
{
6581-
word32 dataSz;
65826581
word32 begin = *idx;
65836582
int ret=WS_SUCCESS;
65846583

6585-
WOLFSSH_UNUSED(ssh);
6586-
WOLFSSH_UNUSED(len);
6587-
65886584
WLOG(WS_LOG_DEBUG, "DoRequestSuccess, *idx=%d, len=%d", *idx, len);
6589-
ato32(buf + begin, &dataSz);
6590-
begin += LENGTH_SZ + dataSz;
6585+
begin += len;
65916586

65926587
if (ssh->ctx->reqSuccessCb != NULL)
65936588
ret = ssh->ctx->reqSuccessCb(ssh, &(buf[*idx]), len, ssh->reqSuccessCtx);
@@ -6599,16 +6594,11 @@ static int DoRequestSuccess(WOLFSSH *ssh, byte *buf, word32 len, word32 *idx)
65996594

66006595
static int DoRequestFailure(WOLFSSH *ssh, byte *buf, word32 len, word32 *idx)
66016596
{
6602-
word32 dataSz;
66036597
word32 begin = *idx;
66046598
int ret = WS_SUCCESS;
66056599

6606-
WOLFSSH_UNUSED(ssh);
6607-
WOLFSSH_UNUSED(len);
6608-
6609-
WLOG(WS_LOG_DEBUG, "DoRequestFalure, *idx=%d, len=%d", *idx, len);
6610-
ato32(buf + begin, &dataSz);
6611-
begin += LENGTH_SZ + dataSz;
6600+
WLOG(WS_LOG_DEBUG, "DoRequestFailure, *idx=%d, len=%d", *idx, len);
6601+
begin += len;
66126602

66136603
if (ssh->ctx->reqFailureCb != NULL)
66146604
ret = ssh->ctx->reqFailureCb(ssh, &(buf[*idx]), len, ssh->reqFailureCtx);

tests/regress.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,30 @@ static void TestGlobalRequestFwdCancelWithCbSendsSuccess(void)
14891489

14901490
FreeChannelOpenHarness(&harness);
14911491
}
1492+
1493+
/* Verify DoRequestSuccess correctly consumes a uint32 port payload (RFC 4254
1494+
* §4) without treating it as a length prefix, which would overrun the buffer
1495+
* and produce WS_BUFFER_E. */
1496+
static void TestRequestSuccessWithPortParsesCorrectly(void)
1497+
{
1498+
ChannelOpenHarness harness;
1499+
byte payload[UINT32_SZ];
1500+
byte in[64];
1501+
word32 inSz;
1502+
word32 idx = 0;
1503+
int ret;
1504+
1505+
idx = AppendUint32(payload, sizeof(payload), idx, 2222);
1506+
inSz = WrapPacket(MSGID_REQUEST_SUCCESS, payload, idx, in, sizeof(in));
1507+
1508+
InitChannelOpenHarness(&harness, in, inSz);
1509+
1510+
ret = DoReceive(harness.ssh);
1511+
1512+
AssertIntEQ(ret, WS_SUCCESS);
1513+
1514+
FreeChannelOpenHarness(&harness);
1515+
}
14921516
#endif
14931517

14941518
#ifdef WOLFSSH_AGENT
@@ -2121,6 +2145,7 @@ int main(int argc, char** argv)
21212145
TestGlobalRequestFwdWithCbSendsSuccess();
21222146
TestGlobalRequestFwdCancelNoCbSendsFailure();
21232147
TestGlobalRequestFwdCancelWithCbSendsSuccess();
2148+
TestRequestSuccessWithPortParsesCorrectly();
21242149
#endif
21252150
#ifdef WOLFSSH_AGENT
21262151
TestAgentChannelNullAgentSendsOpenFail();

0 commit comments

Comments
 (0)