Skip to content

Commit 12754bb

Browse files
Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ad38cc3 commit 12754bb

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

tests/regress.c

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,90 @@ static void AssertChannelOpenFailResponse(const ChannelOpenHarness* harness,
973973
}
974974

975975
#ifdef WOLFSSH_FWD
976+
static word32 ParsePayloadLen(const byte* packet, word32 packetSz)
977+
{
978+
word32 packetLen;
979+
byte padLen;
980+
981+
AssertNotNull(packet);
982+
AssertTrue(packetSz >= 6);
983+
984+
WMEMCPY(&packetLen, packet, sizeof(packetLen));
985+
packetLen = ntohl(packetLen);
986+
padLen = packet[4];
987+
988+
AssertTrue(packetLen >= (word32)padLen + 1);
989+
AssertTrue(packetSz >= packetLen + 4);
990+
991+
return packetLen - padLen - 1;
992+
}
993+
994+
static const byte* ParseGlobalRequestName(const byte* packet, word32 packetSz,
995+
word32* nameSz)
996+
{
997+
word32 packetLen;
998+
word32 payloadLen;
999+
word32 strSz;
1000+
const byte* payload;
1001+
1002+
AssertNotNull(packet);
1003+
AssertNotNull(nameSz);
1004+
AssertTrue(packetSz >= 10);
1005+
1006+
WMEMCPY(&packetLen, packet, sizeof(packetLen));
1007+
packetLen = ntohl(packetLen);
1008+
AssertTrue(packetSz >= packetLen + 4);
1009+
1010+
payloadLen = ParsePayloadLen(packet, packetSz);
1011+
payload = packet + 5;
1012+
1013+
AssertTrue(payloadLen >= 1 + sizeof(word32));
1014+
AssertIntEQ(payload[0], MSGID_GLOBAL_REQUEST);
1015+
1016+
WMEMCPY(&strSz, payload + 1, sizeof(strSz));
1017+
strSz = ntohl(strSz);
1018+
AssertTrue(payloadLen >= 1 + sizeof(word32) + strSz);
1019+
1020+
*nameSz = strSz;
1021+
return payload + 1 + sizeof(word32);
1022+
}
1023+
9761024
static void AssertGlobalRequestReply(const ChannelOpenHarness* harness,
9771025
byte expectedMsgId)
9781026
{
1027+
byte msgId;
1028+
word32 payloadLen;
1029+
9791030
AssertTrue(harness->io.outSz > 0);
980-
AssertIntEQ(ParseMsgId(harness->io.out, harness->io.outSz), expectedMsgId);
1031+
msgId = ParseMsgId(harness->io.out, harness->io.outSz);
1032+
AssertIntEQ(msgId, expectedMsgId);
1033+
1034+
payloadLen = ParsePayloadLen(harness->io.out, harness->io.outSz);
1035+
if (expectedMsgId == MSGID_REQUEST_FAILURE) {
1036+
AssertIntEQ(payloadLen, 1);
1037+
}
1038+
else if (expectedMsgId == MSGID_REQUEST_SUCCESS) {
1039+
const byte* reqName;
1040+
word32 reqNameSz;
1041+
1042+
reqName = ParseGlobalRequestName(harness->io.in, harness->io.inSz,
1043+
&reqNameSz);
1044+
1045+
if (reqNameSz == sizeof("tcpip-forward") - 1 &&
1046+
WMEMCMP(reqName, "tcpip-forward",
1047+
sizeof("tcpip-forward") - 1) == 0) {
1048+
AssertIntEQ(payloadLen, 5);
1049+
}
1050+
else if (reqNameSz == sizeof("cancel-tcpip-forward") - 1 &&
1051+
WMEMCMP(reqName, "cancel-tcpip-forward",
1052+
sizeof("cancel-tcpip-forward") - 1) == 0) {
1053+
AssertIntEQ(payloadLen, 1);
1054+
}
1055+
else {
1056+
Fail(("unexpected global request name"),
1057+
("%.*s", (int)reqNameSz, reqName));
1058+
}
1059+
}
9811060
}
9821061
#endif
9831062

0 commit comments

Comments
 (0)