Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -15420,6 +15420,17 @@ int ValidateProtoId(const char* protoIdStr, word32 len)
}
}

/* softwareversion runs to the first space and must not contain a '-'
* (RFC 4253 section 4.2); the comments may. */
for (i = SSH_PROTO_SZ;
i < len - SSH_PROTO_EOL_SZ && protoIdStr[i] != ' '; i++) {
if (protoIdStr[i] == '-') {
WLOG(WS_LOG_ERROR, "Proto Id was invalid: softwareversion "
"must not contain '-'");
return WS_BAD_ARGUMENT;
}
}

return WS_SUCCESS;
}

Expand Down
8 changes: 7 additions & 1 deletion tests/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ static int test_DoProtoId(void)
* 0x7e must both be accepted. */
{ "body w/ SP comments", "SSH-2.0-app comment\r\n", 1 },
{ "body w/ tilde", "SSH-2.0-app~1\r\n", 1 },
/* RFC 4253 section 4.2 bars '-' only from softwareversion. */
{ "comments w/ minus", "SSH-2.0-app my-comment\r\n", 1 },
{ "comments are minus", "SSH-2.0-app -\r\n", 1 },
/* Failing Tests */
{ "wrong version prefix", "SSH-2-this_is_my_app\r\n", 0 },
{ "bad casing prefix", "sSH-2.0-this_is_my_app\r\n", 0 },
Expand All @@ -675,7 +678,10 @@ static int test_DoProtoId(void)
{ "Body End in CR", "SSH-2.0-s\r\r\n", 0 },
{ "Body End in TAB", "SSH-2.0-s\t\r\n", 0 },
{ "body starts w/ space", "SSH-2.0-\x20-a-b\r\n", 0 },
{ "body has embedded TAB", "SSH-2.0-\x7e-a\t\r\n", 0 },
{ "body has embedded TAB", "SSH-2.0-\x7e" "a\t\r\n", 0 },
{ "swversion w/ minus", "SSH-2.0-my-app\r\n", 0 },
{ "swversion is minus", "SSH-2.0--\r\n", 0 },
{ "minus before comments", "SSH-2.0-app- comment\r\n", 0 },
{ "too long id", tooLongProtoId, 0 },
{ "null pointer", NULL, 0 },
};
Expand Down
2 changes: 2 additions & 0 deletions wolfssh/ssh.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,8 @@ WOLFSSH_API int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx, const char* newBanner);
* body as softwareversion [SP comments], so a leading space would
* make softwareversion empty. A space later in the body is accepted
* and starts the optional comments field.
* MUST NOT carry a '-' in softwareversion, the body up to the first
* space (RFC 4253 section 4.2). The comments may carry one.
* If these are not adhered to the function will return WS_BAD_ARGUMENT
* and not load the ProtoId into the WOLFSSH_CTX struct.
* ProtoIdStr is stored by reference and is not copied, so it must remain
Expand Down
Loading