{"record":{"id":"f80f0835fa55fb52","repo":"TechnitiumSoftware/DnsServer","slug":"qpm-limit-ipv4-prefix-valid-range-is-between-0-and","errorCode":null,"errorMessage":"QPM limit IPv4 prefix valid range is between 0 and 32.","messagePattern":"QPM limit IPv4 prefix valid range is between 0 and 32\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/DnsServer.cs","lineNumber":7418,"sourceCode":"        public IReadOnlyDictionary<int, (int, int)> QpmPrefixLimitsIPv4\n        {\n            get { return _qpmPrefixLimitsIPv4; }\n            set\n            {\n                if (value is null)\n                {\n                    _qpmPrefixLimitsIPv4 = new Dictionary<int, (int, int)>();\n                }\n                else if (value.Count > byte.MaxValue)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM Prefix Limits for IPv4 cannot have more than 255 entries.\");\n                }\n                else\n                {\n                    foreach (KeyValuePair<int, (int, int)> qpmPrefixLimit in value)\n                    {\n                        if ((qpmPrefixLimit.Key < 0) || (qpmPrefixLimit.Key > 32))\n                            throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM limit IPv4 prefix valid range is between 0 and 32.\");\n\n                        if ((qpmPrefixLimit.Value.Item1 < 0) || (qpmPrefixLimit.Value.Item2 < 0))\n                            throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM limit value cannot be less than 0.\");\n                    }\n\n                    _qpmPrefixLimitsIPv4 = value;\n                }\n\n                ResetQpsLimitTimer();\n            }\n        }\n\n        public IReadOnlyDictionary<int, (int, int)> QpmPrefixLimitsIPv6\n        {\n            get { return _qpmPrefixLimitsIPv6; }\n            set\n            {\n                if (value is null)","sourceCodeStart":7400,"sourceCodeEnd":7436,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/DnsServer.cs#L7400-L7436","documentation":"Thrown by the QpmPrefixLimitsIPv4 property setter when any dictionary key (IPv4 prefix length) is outside 0-32. IPv4 addresses are 32 bits, so prefix lengths beyond that are invalid. Each entry is validated in a loop before assignment.","triggerScenarios":"Assigning QpmPrefixLimitsIPv4 a dictionary containing a key < 0 or > 32.","commonSituations":"Reusing an IPv6 prefix-length list (up to 128) for the IPv4 limits; off-by-one in generated config; typo in a manually-edited settings file.","solutions":["Ensure all keys are integers in the range 0-32 inclusive.","Filter the dictionary before assignment to drop out-of-range keys."],"exampleFix":"// before\nserver.QpmPrefixLimitsIPv4 =\n    new Dictionary<int,(int,int)> { { 64, (100, 200) } }; // throws\n\n// after\nserver.QpmPrefixLimitsIPv4 =\n    new Dictionary<int,(int,int)> { { 24, (100, 200) } };","handlingStrategy":"validation","validationCode":"foreach (var key in qpmV4.Keys)\n    if (key < 0 || key > 32)\n        throw new InvalidOperationException($\"Invalid IPv4 prefix key: {key}\");\nserver.QpmPrefixLimitsIPv4 = qpmV4;","typeGuard":"static bool IsValidV4PrefixKey(int key) => key >= 0 && key <= 32;","tryCatchPattern":"try { server.QpmPrefixLimitsIPv4 = qpmV4; }\ncatch (ArgumentOutOfRangeException) { qpmV4 = qpmV4.Where(kv => kv.Key >= 0 && kv.Key <= 32).ToDictionary(k=>k.Key,v=>v.Value); server.QpmPrefixLimitsIPv4 = qpmV4; }","preventionTips":["Validate keys are in 0-32 before building the dictionary.","Do not reuse IPv6 prefix lists for the IPv4 property."],"tags":["dns","qpm","rate-limiting","ipv4","validation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}