From f0caefcc334e0c788e29cc4621dc93d3b2fa5b37 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Thu, 28 Jul 2022 13:21:42 -0700 Subject: [PATCH] Make HandlePort use GetConfigInt and add 0 port test. --- apps/wolfsshd/configuration.c | 8 ++++---- apps/wolfsshd/test/test_configuration.c | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/wolfsshd/configuration.c b/apps/wolfsshd/configuration.c index 5d9a6770..c61830de 100644 --- a/apps/wolfsshd/configuration.c +++ b/apps/wolfsshd/configuration.c @@ -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; } diff --git a/apps/wolfsshd/test/test_configuration.c b/apps/wolfsshd/test/test_configuration.c index 91da4076..34da542a 100644 --- a/apps/wolfsshd/test/test_configuration.c +++ b/apps/wolfsshd/test/test_configuration.c @@ -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},