{"record":{"id":"80aae9c234928905","repo":"TechnitiumSoftware/DnsServer","slug":"seconds-elapsed-must-be-2-bytes","errorCode":null,"errorMessage":"Seconds elapsed must be 2 bytes.","messagePattern":"Seconds elapsed must be 2 bytes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpMessage.cs","lineNumber":119,"sourceCode":"            if (yiaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(yiaddr));\n\n            if (siaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(siaddr));\n\n            if (giaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(giaddr));\n\n            ArgumentNullException.ThrowIfNull(clientHardwareAddress);\n\n            if (clientHardwareAddress.Length > 16)\n                throw new ArgumentException(\"Client hardware address cannot exceed 16 bytes.\", nameof(clientHardwareAddress));\n\n            if (xid.Length != 4)\n                throw new ArgumentException(\"Transaction ID must be 4 bytes.\", nameof(xid));\n\n            if (secs.Length != 2)\n                throw new ArgumentException(\"Seconds elapsed must be 2 bytes.\", nameof(secs));\n\n            _op = op;\n            _htype = hardwareAddressType;\n            _hlen = Convert.ToByte(clientHardwareAddress.Length);\n            _hops = 0;\n\n            _xid = xid;\n\n            _secs = secs;\n            _flags = flags;\n\n            _ciaddr = ciaddr;\n            _yiaddr = yiaddr;\n            _siaddr = siaddr;\n            _giaddr = giaddr;\n\n            _clientHardwareAddress = clientHardwareAddress;\n            _chaddr = new byte[16];","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpMessage.cs#L101-L137","documentation":"Constructor argument guard in DhcpMessage: the seconds-elapsed (secs) field must be exactly 2 bytes. RFC 2131 defines secs as a 2-octet field recording seconds since the client began the address acquisition process; other lengths are invalid wire data.","triggerScenarios":"Calling the DhcpMessage constructor with a secs byte array whose Length is not 2.","commonSituations":"Passing a ushort/int directly instead of its 2-byte form; creating secs from the wrong buffer slice; a helper that emits 4 bytes (uint) instead of 2.","solutions":["Build secs as exactly 2 bytes using BitConverter.GetBytes((ushort)seconds) in the correct endianness (network byte order).","When forwarding a parsed packet, reuse its original 2-byte secs slice.","Validate secs.Length == 2 before constructing.","Do not pass a full int/uint representation."],"exampleFix":"// before\nbyte[] secs = BitConverter.GetBytes(0u); // 4 bytes\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ...); // throws [217]\n\n// after: 2 bytes, network order\nushort s = 0;\nbyte[] secs = new byte[] { (byte)(s >> 8), (byte)(s & 0xff) };\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ...);","handlingStrategy":"validation","validationCode":"if (secs is null) throw new ArgumentNullException(nameof(secs));\nif (secs.Length != 2) throw new ArgumentException(\"Seconds elapsed (secs) must be exactly 2 bytes.\", nameof(secs));\n\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","typeGuard":"static bool IsValidSecs(byte[] secs) =>\n    secs is not null && secs.Length == 2;","tryCatchPattern":null,"preventionTips":["Build secs as 2 bytes (network order), not a 4-byte uint.","Reuse the parsed packet's secs slice when forwarding.","Validate length before constructing."],"tags":["dhcp","validation","constructor","rfc2131","seconds"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}