{"record":{"id":"4eb07dff12d00002","repo":"TechnitiumSoftware/DnsServer","slug":"invalid-cache-maximum-entries-value-valid-range-i","errorCode":null,"errorMessage":"Invalid cache maximum entries value. Valid range is 0 and above.","messagePattern":"Invalid cache maximum entries value\\. Valid range is 0 and above\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs","lineNumber":1237,"sourceCode":"        public uint ServeStaleResetTtl\n        {\n            get { return _serveStaleResetTtl; }\n            set\n            {\n                if ((value < SERVE_STALE_MIN_RESET_TTL) || (value > SERVE_STALE_MAX_RESET_TTL))\n                    throw new ArgumentOutOfRangeException(nameof(ServeStaleResetTtl), \"Serve stale reset TTL must be between \" + SERVE_STALE_MIN_RESET_TTL + \" and \" + SERVE_STALE_MAX_RESET_TTL + \" seconds. Recommended value is 30 seconds.\");\n\n                _serveStaleResetTtl = value;\n            }\n        }\n\n        public long MaximumEntries\n        {\n            get { return _maximumEntries; }\n            set\n            {\n                if (value < 0)\n                    throw new ArgumentOutOfRangeException(nameof(MaximumEntries), \"Invalid cache maximum entries value. Valid range is 0 and above.\");\n\n                _maximumEntries = value;\n            }\n        }\n\n        public long TotalEntries\n        { get { return _totalEntries; } }\n\n        #endregion\n    }\n}\n","sourceCodeStart":1219,"sourceCodeEnd":1249,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs#L1219-L1249","documentation":"Thrown by the MaximumEntries property setter when value is less than 0. The cache maximum-entries cap must be zero or positive (0 typically means unlimited/auto), so any negative number is rejected.","triggerScenarios":"Setting MaximumEntries to a negative number; arithmetic that underflows (e.g. subtracting from a base); config import with a bad value.","commonSituations":"Script computes capacity from memory/disk and produces a negative; typo/negative literal; stale config value.","solutions":["Pass 0 (unlimited) or a positive number for MaximumEntries.","Clamp computed values to >= 0 before assigning.","Validate the configured value against the documented range before applying."],"exampleFix":"// before\n_cacheZoneManager.MaximumEntries = -1; // < 0 -> throws\n// after\n_cacheZoneManager.MaximumEntries = 0; // 0 = unlimited, or use a positive cap","handlingStrategy":"validation","validationCode":"long max = requestedMaximumEntries < 0 ? 0 : requestedMaximumEntries;\ncacheZoneManager.MaximumEntries = max;","typeGuard":"static bool IsValidMaximumEntries(long v) => v >= 0;","tryCatchPattern":"try { cacheZoneManager.MaximumEntries = value; }\ncatch (ArgumentOutOfRangeException) { cacheZoneManager.MaximumEntries = Math.Max(0, value); }","preventionTips":["Clamp capacity computations to >= 0.","Use 0 for unlimited when unsure.","Validate config-sourced values before applying.","Guard against arithmetic underflow in size calculations."],"tags":["dns","cache","validation","configuration"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}