From f07c5235433d630c4e5d53e2e870f036d2324a6c Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Mon, 19 Aug 2019 11:34:34 +0200 Subject: [PATCH] net/cmdline: better checks for TCP port values --- cmdline.cc | 4 ++++ net.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmdline.cc b/cmdline.cc index ed31a62..91dae4e 100644 --- a/cmdline.cc +++ b/cmdline.cc @@ -487,6 +487,10 @@ std::unique_ptr parseArgs(int argc, char* argv[]) { nsjconf->chroot = optarg; break; case 'p': + if (!util::isANumber(optarg)) { + LOG_E("Couldn't parse TCP port '%s'", optarg); + return nullptr; + } nsjconf->port = strtoumax(optarg, NULL, 0); nsjconf->mode = MODE_LISTEN_TCP; break; diff --git a/net.cc b/net.cc index 9220022..6e5745a 100644 --- a/net.cc +++ b/net.cc @@ -205,7 +205,7 @@ bool limitConns(nsjconf_t* nsjconf, int connsock) { } int getRecvSocket(const char* bindhost, int port) { - if (port < 1 || port > 65535) { + if (port < 0 || port > 65535) { LOG_F( "TCP port %d out of bounds (0 <= port <= 65535), specify one with --port " "", -- 2.7.4