[NTOS:KD] DbgKdGetStringApi implementation: Ensure the returned string is NULL-terminated.

Addendum to commit 84e32e4e.

Explain more accurately what's going on regarding the returned string
and the inaccurate claims made in the official DbgPrompt documentation
in MSDN. (Has been verified by looking through the traffic in WinDbg
debugging of Windows and ReactOS.)
This commit is contained in:
Hermès Bélusca-Maïto 2023-03-22 19:45:33 +01:00
parent 9d9536d431
commit fe81656776
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -726,17 +726,24 @@ KdReceivePacket(
if (!(KdbDebugState & KD_DEBUG_KDSERIAL))
KbdDisableMouse();
/* Read a line of user input and retrieve the length.
* The output string is NULL-terminated -- documentation states
* that DbgPrompt() does not NULL-terminate, but it does. */
*DataLength = KdbpReadCommand(ResponseString.Buffer,
/*
* Read a NULL-terminated line of user input and retrieve its length.
* Official documentation states that DbgPrompt() includes a terminating
* newline character but does not NULL-terminate. However, experiments
* show that this behaviour is left at the discretion of WinDbg itself.
* WinDbg NULL-terminates the string unless its buffer is too short,
* in which case the string is simply truncated without NULL-termination.
*/
ResponseString.Length =
(USHORT)KdbpReadCommand(ResponseString.Buffer,
ResponseString.MaximumLength);
if (!(KdbDebugState & KD_DEBUG_KDSERIAL))
KbdEnableMouse();
/* Return the length */
*DataLength = min(*DataLength, DebugIo->u.GetString.LengthOfStringRead);
/* Adjust and return the string length */
*DataLength = min(ResponseString.Length + sizeof(ANSI_NULL),
DebugIo->u.GetString.LengthOfStringRead);
MessageData->Length = DebugIo->u.GetString.LengthOfStringRead = *DataLength;
/* Only now we can copy back the data into MessageData->Buffer */