Skip to content

Commit 0317c40

Browse files
Fix DoChannelOpen() and Add regress test
1 parent 9c8b4e8 commit 0317c40

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/internal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8739,6 +8739,12 @@ static int DoChannelOpen(WOLFSSH* ssh,
87398739
ssh->fwdCbCtx, NULL, newChannel->channel);
87408740
}
87418741
}
8742+
else {
8743+
WLOG(WS_LOG_WARN, "No forward callback set for direct-tcpip channel,"
8744+
" failing channel open");
8745+
fail_reason = OPEN_ADMINISTRATIVELY_PROHIBITED;
8746+
ret = WS_ERROR;
8747+
}
87428748
}
87438749
#endif /* WOLFSSH_FWD */
87448750
if (ret == WS_SUCCESS) {

tests/regress.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,29 @@ static void TestDirectTcpipRejectSendsOpenFail(void)
11841184

11851185
FreeChannelOpenHarness(&harness);
11861186
}
1187+
1188+
static void TestDirectTcpipNoFwdCbSendsOpenFail(void)
1189+
{
1190+
ChannelOpenHarness harness;
1191+
byte extra[128];
1192+
byte in[192];
1193+
word32 extraSz;
1194+
word32 inSz;
1195+
int ret;
1196+
1197+
extraSz = BuildDirectTcpipExtra("127.0.0.1", 8080, "127.0.0.1", 2222,
1198+
extra, sizeof(extra));
1199+
inSz = BuildChannelOpenPacket("direct-tcpip", 9, 0x4000, 0x8000,
1200+
extra, extraSz, in, sizeof(in));
1201+
1202+
InitChannelOpenHarness(&harness, in, inSz);
1203+
/* Intentionally do NOT register fwdCb */
1204+
1205+
ret = DoReceive(harness.ssh);
1206+
AssertChannelOpenFailResponse(&harness, ret);
1207+
1208+
FreeChannelOpenHarness(&harness);
1209+
}
11871210
#endif
11881211

11891212
#ifdef WOLFSSH_AGENT
@@ -1648,6 +1671,7 @@ int main(int argc, char** argv)
16481671
TestChannelOpenCallbackRejectSendsOpenFail();
16491672
#ifdef WOLFSSH_FWD
16501673
TestDirectTcpipRejectSendsOpenFail();
1674+
TestDirectTcpipNoFwdCbSendsOpenFail();
16511675
#endif
16521676
#ifdef WOLFSSH_AGENT
16531677
TestAgentChannelNullAgentSendsOpenFail();

0 commit comments

Comments
 (0)