{"record":{"id":"93704fca73a21241","repo":"TechnitiumSoftware/DnsServer","slug":"boot-file-name-cannot-exceed-127-bytes","errorCode":null,"errorMessage":"Boot file name cannot exceed 127 bytes.","messagePattern":"Boot file name cannot exceed 127 bytes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpMessage.cs","lineNumber":159,"sourceCode":"            if (sname != null)\n            {\n                _serverHostName = sname;\n\n                byte[] buffer = Encoding.ASCII.GetBytes(sname);\n                if (buffer.Length >= 64)\n                    throw new ArgumentException(\"Server host name cannot exceed 63 bytes.\", nameof(sname));\n\n                Buffer.BlockCopy(buffer, 0, _sname, 0, buffer.Length);\n            }\n\n            _file = new byte[128];\n            if (file != null)\n            {\n                _bootFileName = file;\n\n                byte[] buffer = Encoding.ASCII.GetBytes(file);\n                if (buffer.Length >= 128)\n                    throw new ArgumentException(\"Boot file name cannot exceed 127 bytes.\", nameof(file));\n\n                Buffer.BlockCopy(buffer, 0, _file, 0, buffer.Length);\n            }\n\n            _options = options;\n\n            foreach (DhcpOption option in _options)\n            {\n                if (option.Code == DhcpOptionCode.ServerIdentifier)\n                {\n                    _serverIdentifier = option as ServerIdentifierOption;\n                    break;\n                }\n            }\n        }\n\n        public DhcpMessage(Stream s)\n        {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpMessage.cs#L141-L177","documentation":"Constructor argument guard in DhcpMessage: the boot file name (file) must be at most 127 ASCII bytes. RFC 2131 fixes the 'file' field at 128 bytes (127 usable + a null terminator); the constructor ASCII-encodes file and rejects a result of 128+ bytes. The check uses >= 128, so up to 127 bytes are allowed.","triggerScenarios":"Calling the DhcpMessage constructor with a non-null file whose ASCII encoding is 128 or more bytes.","commonSituations":"A long boot image path with many directory segments; a full URL placed in the file field instead of a path; iPXE scripts/embedded data; a deeply nested TFTP path.","solutions":["Use a boot file path whose ASCII encoding is <= 127 bytes.","Store only the path (not a full URL or embedded script) in the file field; move long payloads to DHCP options (e.g. option 66/67 or vendor options).","Validate Encoding.ASCII.GetByteCount(file) < 128 before constructing.","Shorten directory structure / use a shorter filename on the TFTP server."],"exampleFix":"// before\nstring file = \"https://tftp.example.corp.local/boot/very/deeply/nested/path/to/this/image/bootstrap-image-filename.bin\"; // > 127 bytes\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts); // throws [219]\n\n// after: bare path within 127 bytes\nstring file = \"/boot/pxelinux.0\";\nif (Encoding.ASCII.GetByteCount(file) >= 128) throw new InvalidOperationException(\"file too long\");\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts);","handlingStrategy":"validation","validationCode":"if (file is not null && Encoding.ASCII.GetByteCount(file) >= 128)\n    throw new ArgumentException(\"Boot file name (file) must be <= 127 ASCII bytes.\", nameof(file));\n\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","typeGuard":"static bool IsValidBootFile(string file) =>\n    file is null || Encoding.ASCII.GetByteCount(file) < 128;","tryCatchPattern":null,"preventionTips":["Store only the boot file path in the file field, not a full URL or embedded script.","Validate ASCII byte count < 128 before constructing.","Move long payloads to DHCP options (e.g. option 66/67)."],"tags":["dhcp","validation","constructor","rfc2131","boot-file"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}