{"record":{"id":"39b2538713ac86d5","repo":"shadowsocks/shadowsocks-windows","slug":"port-out-of-range","errorCode":null,"errorMessage":"Port out of range","messagePattern":"Port out of range","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"shadowsocks-csharp/Model/Configuration.cs","lineNumber":355,"sourceCode":"                config.configs.Insert(index.GetValueOrDefault(config.configs.Count), server);\r\n\r\n                //if (index.HasValue)\r\n                //    config.configs.Insert(index.Value, server);\r\n                //else\r\n                //    config.configs.Add(server);\r\n            }\r\n            return server;\r\n        }\r\n\r\n        public static Server GetDefaultServer()\r\n        {\r\n            return new Server();\r\n        }\r\n\r\n        public static void CheckPort(int port)\r\n        {\r\n            if (port <= 0 || port > 65535)\r\n                throw new ArgumentException(I18N.GetString(\"Port out of range\"));\r\n        }\r\n\r\n        public static void CheckLocalPort(int port)\r\n        {\r\n            CheckPort(port);\r\n            if (port == 8123)\r\n                throw new ArgumentException(I18N.GetString(\"Port can't be 8123\"));\r\n        }\r\n\r\n        private static void CheckPassword(string password)\r\n        {\r\n            if (string.IsNullOrEmpty(password))\r\n                throw new ArgumentException(I18N.GetString(\"Password can not be blank\"));\r\n        }\r\n\r\n        public static void CheckServer(string server)\r\n        {\r\n            if (string.IsNullOrEmpty(server))\r","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/shadowsocks/shadowsocks-windows/blob/891d971682eefcaa2e640258d3b352a3ad3b2233/shadowsocks-csharp/Model/Configuration.cs#L337-L373","documentation":"ArgumentException thrown by CheckPort when a port is <= 0 or > 65535. Valid TCP/UDP ports are 1..65535. This is part of the server-config validation flow (also reached via CheckLocalPort) used when loading or saving a Shadowsocks server entry.","triggerScenarios":"A user enters 0, a negative number, or a value above 65535 in the server config dialog. gui-config.json is hand-edited with an out-of-range server_port. An int parse of an oversized port string overflows the valid range.","commonSituations":"Typo such as 65536 or 808080. Port field left blank (parsed as 0). Copy-paste of a port that included extra digits.","solutions":["Set the port to a value in 1..65535, preferring the non-privileged range 1024..65535.","Re-open the config dialog and correct the entry, then save.","Manually fix the server_port field in gui-config.json and reload."],"exampleFix":"// before\nConfiguration.CheckPort(70000); // throws\n\n// after\nint port = 70000;\nif (port < 1 || port > 65535) port = 8388; // sane default\nConfiguration.CheckPort(port);","handlingStrategy":"validation","validationCode":"static bool IsValidPort(int p) => p > 0 && p <= 65535;\nif (!IsValidPort(port)) {\n    // reject in the UI before calling CheckPort\n    return;\n}","typeGuard":null,"tryCatchPattern":"try { Configuration.CheckPort(port); }\ncatch (ArgumentException ex) { /* show ex.Message in the UI, keep the dialog open */ }","preventionTips":["Clamp port input in the GUI to 1..65535.","Validate gui-config.json on load and reject out-of-range values."],"tags":["configuration","validation","port","networking"],"backgroundTag":null,"analyzedSha":"891d971682eefcaa2e640258d3b352a3ad3b2233","analyzedAt":"2026-08-13T10:12:34.434Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}