Make HandlePort use GetConfigInt and add 0 port test.

pull/435/head
Hayden Roche 2022-07-28 13:21:42 -07:00
parent 90769af1f8
commit f0caefcc33
2 changed files with 5 additions and 4 deletions

View File

@ -329,16 +329,16 @@ static int HandlePwAuth(WOLFSSHD_CONFIG* conf, const char* value)
static int HandlePort(WOLFSSHD_CONFIG* conf, const char* value)
{
int ret = WS_SUCCESS;
int portInt;
long portInt;
if (conf == NULL || value == NULL) {
ret = WS_BAD_ARGUMENT;
}
if (ret == WS_SUCCESS) {
portInt = XATOI(value);
portInt = GetConfigInt(value, WSTRLEN(value), 0, conf->heap);
if (portInt <= 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Unable to parse port number: %s.",
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid port number: %s.",
value);
ret = WS_BAD_ARGUMENT;
}
@ -347,7 +347,7 @@ static int HandlePort(WOLFSSHD_CONFIG* conf, const char* value)
conf->port = (word16)portInt;
}
else {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Port number %d too big.",
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Port number %ld too big.",
portInt);
ret = WS_BAD_ARGUMENT;
}

View File

@ -67,6 +67,7 @@ static int test_ParseConfigLine(void)
{"Valid port", "Port 22", 0},
{"Port too big", "Port 65536", 1},
{"Negative port", "Port -99", 1},
{"Port 0", "Port 0", 1},
{"Port NaN", "Port wolfsshd", 1},
{"Port no value", "Port \n", 1},