net/cmdline: better checks for TCP port values

This commit is contained in:
Robert Swiecki 2019-08-19 11:34:34 +02:00
parent 2044488520
commit f07c523543
2 changed files with 5 additions and 1 deletions

View File

@ -487,6 +487,10 @@ std::unique_ptr<nsjconf_t> 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;

2
net.cc
View File

@ -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 "
"<port>",