Skip to content

Commit bbd4d0c

Browse files
committed
Document the wolfSSH_SetChannelType contract
The refusals added for names the peer cannot use changed the return contract of a public API whose block comment still promised only WS_SUCCESS. There is no dox_comments entry, so that comment is all an embedder has. - Spell out each WS_BAD_ARGUMENT case, the keep-the-stored-name rule, and that a refused call leaves the selected type alone. - api.c asserts connectChannelId across the refusals. It is the field SendChannelRequest() switches on, so moving the checks back below the assignment would otherwise pass.
1 parent e0118c5 commit bbd4d0c

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/ssh.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,18 @@ int wolfSSH_SetExitStatus(WOLFSSH* ssh, word32 exitStatus)
16451645
* name name or command in the case of subsystem and exec channel types
16461646
* nameSz size of name buffer
16471647
*
1648+
* Exec and subsystem carry a name string the peer requires, so one must be
1649+
* available. Passing none keeps the name an earlier call stored; with
1650+
* nothing stored the call is refused rather than sending a request the peer
1651+
* reads as malformed. Shell and terminal take no name and drop any stored
1652+
* one. A refused call changes nothing, the selected type included.
1653+
*
16481654
* returns WS_SUCCESS on success
1655+
* returns WS_BAD_ARGUMENT for a NULL ssh or an unknown type, for exec on
1656+
* the server side, for a name at or above WOLFSSH_MAX_CHN_NAMESZ, for a
1657+
* nameSz with no name behind it, and for exec or subsystem with no name
1658+
* given and none stored
1659+
* returns WS_MEMORY_E if the name cannot be allocated
16491660
*/
16501661
int wolfSSH_SetChannelType(WOLFSSH* ssh, byte type, byte* name, word32 nameSz)
16511662
{

tests/api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,20 @@ static void test_wolfSSH_SetChannelType(void)
317317
AssertIntEQ(WS_BAD_ARGUMENT, wolfSSH_SetChannelType(ssh,
318318
WOLFSSH_SESSION_SUBSYSTEM, NULL, 0));
319319
AssertNull(ssh->channelName);
320+
/* a refused call leaves the selected type alone, not just the name */
321+
AssertIntEQ(WOLFSSH_SESSION_SHELL, ssh->connectChannelId);
320322

321323
/* likewise for a size with no name behind it */
322324
AssertIntEQ(WS_BAD_ARGUMENT, wolfSSH_SetChannelType(ssh,
323325
WOLFSSH_SESSION_SUBSYSTEM, NULL, 4));
324326
AssertNull(ssh->channelName);
327+
AssertIntEQ(WOLFSSH_SESSION_SHELL, ssh->connectChannelId);
325328

326329
/* an oversized name is reported, not silently dropped */
327330
AssertIntEQ(WS_BAD_ARGUMENT, wolfSSH_SetChannelType(ssh,
328331
WOLFSSH_SESSION_SUBSYSTEM, (byte*)sub1, WOLFSSH_MAX_CHN_NAMESZ));
329332
AssertNull(ssh->channelName);
333+
AssertIntEQ(WOLFSSH_SESSION_SHELL, ssh->connectChannelId);
330334

331335
AssertIntEQ(WS_SUCCESS, wolfSSH_SetChannelType(ssh,
332336
WOLFSSH_SESSION_SUBSYSTEM, (byte*)sub1,
@@ -347,6 +351,7 @@ static void test_wolfSSH_SetChannelType(void)
347351
AssertIntEQ(WS_BAD_ARGUMENT, wolfSSH_SetChannelType(ssh,
348352
WOLFSSH_SESSION_SUBSYSTEM, (byte*)sub1, WOLFSSH_MAX_CHN_NAMESZ));
349353
AssertIntEQ(1, ssh->channelName == prevName);
354+
AssertIntEQ(WOLFSSH_SESSION_SUBSYSTEM, ssh->connectChannelId);
350355
AssertIntEQ((int)(sizeof(sub1) - 1), (int)ssh->channelNameSz);
351356
AssertIntEQ(0, strcmp((const char*)ssh->channelName, (const char*)sub1));
352357

0 commit comments

Comments
 (0)