{"record":{"id":"1b84ccf299a24d92","repo":"jstedfast/MailKit","slug":"message-ntlmmessagebase","errorCode":null,"errorMessage":"message","messagePattern":"message","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/NtlmMessageBase.cs","lineNumber":81,"sourceCode":"\t\t\tmessage[11] = (byte)(Type >> 24);\n\n\t\t\treturn message;\n\t\t}\n\n\t\tbool CheckSignature (byte[] message, int startIndex)\n\t\t{\n\t\t\tfor (int i = 0; i < Signature.Length; i++) {\n\t\t\t\tif (message[startIndex + i] != Signature[i])\n\t\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn BitConverterLE.ToUInt32 (message, startIndex + 8) == Type;\n\t\t}\n\n\t\tprotected void ValidateArguments (byte[] message, int startIndex, int length)\n\t\t{\n\t\t\tif (message == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (message));\n\n\t\t\tif (startIndex < 0 || startIndex > message.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (startIndex));\n\n\t\t\tif (length < 12 || length > (message.Length - startIndex))\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (length));\n\n\t\t\tif (!CheckSignature (message, startIndex))\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\n\t\t\tvar messageType = BitConverterLE.ToUInt32 (message, 8);\n\t\t\tif (messageType != Type)\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\t\t}\n\n\t\tpublic abstract byte[] Encode ();\n\t}\n}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/NtlmMessageBase.cs#L63-L99","documentation":"Guard in NtlmMessageBase.ValidateArguments, a shared validation helper called by NTLM message Encode/Decode paths: the 'message' byte array to encode into or decode from was null, so ArgumentNullException is thrown before the startIndex/length range checks.","triggerScenarios":"Calling a message constructor/decoder such as new NtlmNegotiateMessage(null) or NtlmChallengeMessage(null, 0) with a null buffer — usually because the server response was never read or a decode call returned null.","commonSituations":"Reading the server's Type2 response from a stream that returned nothing; storing the raw bytes in a field that was never initialized.","solutions":["Read the raw server response bytes before constructing the message and null-check them.","Guard the network read: fail with a clear 'server did not send an NTLM challenge' error rather than passing null.","If the buffer may be absent, skip NTLM authentication instead of constructing the message."],"exampleFix":"// before\nvar challenge = new NtlmChallengeMessage(challengeBytes, 0); // challengeBytes == null\n// after\nif (challengeBytes == null) throw new InvalidOperationException(\"Server did not provide an NTLM challenge.\");\nvar challenge = new NtlmChallengeMessage(challengeBytes, 0);","handlingStrategy":"validation","validationCode":"if (rawMessage == null) throw new InvalidOperationException(\"No NTLM message bytes received from server.\");\nvar msg = new NtlmChallengeMessage(rawMessage, 0);","typeGuard":"static bool IsValidNtlmBuffer(byte[]? message) => message != null && message.Length >= 12;","tryCatchPattern":"try {\n\tmsg = new NtlmChallengeMessage(rawMessage, 0);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"message\") {\n\t// the read produced no data; treat as missing server challenge\n\tthrow new InvalidOperationException(\"Server did not send an NTLM challenge.\", ex);\n}","preventionTips":["Check the network read result before constructing message objects.","Require at least 12 bytes (the NTLMSSP header) before parsing.","Wrap raw response parsing so nulls become protocol-level errors."],"tags":["null-argument","csharp","ntlm","message-parsing"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}