@@ -994,12 +994,14 @@ bool AppInitParameterInteraction(const ArgsManager& args)
994994 int nBind = std::max (nUserBind, size_t (1 ));
995995 // Maximum number of connections with other nodes, this accounts for all types of outbounds and inbounds except for manual
996996 int user_max_connection = args.GetIntArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
997- nMaxConnections = std::max (user_max_connection, 0 );
997+ if (user_max_connection < 0 ) {
998+ return InitError (Untranslated (" -maxconnections must be greater or equal than zero" ));
999+ }
9981000 // Reserve enough FDs to account for the bare minimum, plus any manual connections, plus the bound interfaces
9991001 int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + nBind;
10001002
10011003 // Try raising the FD limit to what we need (available_fds may be smaller than the requested amount if this fails)
1002- available_fds = RaiseFileDescriptorLimit (nMaxConnections + min_required_fds);
1004+ available_fds = RaiseFileDescriptorLimit (user_max_connection + min_required_fds);
10031005 // If we are using select instead of poll, our actual limit may be even smaller
10041006#ifndef USE_POLL
10051007 available_fds = std::min (FD_SETSIZE, available_fds);
@@ -1008,7 +1010,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10081010 return InitError (strprintf (_ (" Not enough file descriptors available. %d available, %d required." ), available_fds, min_required_fds));
10091011
10101012 // Trim requested connection counts, to fit into system limitations
1011- nMaxConnections = std::min (available_fds - min_required_fds, nMaxConnections );
1013+ nMaxConnections = std::min (available_fds - min_required_fds, user_max_connection );
10121014
10131015 if (nMaxConnections < user_max_connection)
10141016 InitWarning (strprintf (_ (" Reducing -maxconnections from %d to %d, because of system limitations." ), user_max_connection, nMaxConnections));
0 commit comments