Author: hbelusca
Date: Wed Jun 8 00:27:25 2016
New Revision: 71593
URL: http://svn.reactos.org/svn/reactos?rev=71593&view=rev
Log:
[CONSRV]
Only add a history entry if console echo is enabled. This ensures that anything sent to the console when echo is disabled (e.g. binary data, or secrets like passwords...) does not remain stored in memory.
Modified:
trunk/reactos/win32ss/user/winsrv/consrv/lineinput.c
Modified: trunk/reactos/win32ss/user/winsrv/consrv/lineinput.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/lineinput.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/lineinput.c [iso-8859-1] Wed Jun 8 00:27:25 2016
@@ -60,7 +60,7 @@
LineInputSetPos(PCONSRV_CONSOLE Console,
UINT Pos)
{
- if (Pos != Console->LinePos && GetConsoleInputBufferMode(Console) & ENABLE_ECHO_INPUT)
+ if (Pos != Console->LinePos && (GetConsoleInputBufferMode(Console) & ENABLE_ECHO_INPUT))
{
PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
SHORT OldCursorX = Buffer->CursorPosition.X;
@@ -95,7 +95,7 @@
if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return;
ActiveBuffer = (PTEXTMODE_SCREEN_BUFFER)Console->ActiveBuffer;
- /* Make sure there's always enough room for ending \r\n */
+ /* Make sure there is always enough room for ending \r\n */
if (NewSize + 2 > Console->LineMaxSize)
return;
@@ -182,7 +182,7 @@
{
case VK_ESCAPE:
{
- /* Clear entire line */
+ /* Clear the entire line */
LineInputSetPos(Console, 0);
LineInputEdit(Console, Console->LineSize, 0, NULL);
@@ -197,7 +197,7 @@
case VK_HOME:
{
- /* Move to start of line. With CTRL, erase everything left of cursor */
+ /* Move to start of line. With CTRL, erase everything left of cursor. */
LineInputSetPos(Console, 0);
if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
LineInputEdit(Console, Pos, 0, NULL);
@@ -206,7 +206,7 @@
case VK_END:
{
- /* Move to end of line. With CTRL, erase everything right of cursor */
+ /* Move to end of line. With CTRL, erase everything right of cursor. */
if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
LineInputEdit(Console, Console->LineSize - Pos, 0, NULL);
else
@@ -216,7 +216,7 @@
case VK_LEFT:
{
- /* Move left. With CTRL, move to beginning of previous word */
+ /* Move to the left. With CTRL, move to beginning of previous word. */
if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
{
while (Pos > 0 && Console->LineBuffer[Pos - 1] == L' ') Pos--;
@@ -233,7 +233,7 @@
case VK_RIGHT:
case VK_F1:
{
- /* Move right. With CTRL, move to beginning of next word */
+ /* Move to the right. With CTRL, move to beginning of next word. */
if (KeyEvent->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
{
while (Pos < Console->LineSize && Console->LineBuffer[Pos] != L' ') Pos++;
@@ -262,7 +262,7 @@
case VK_DELETE:
{
- /* Remove character to right of cursor */
+ /* Remove one character to right of cursor */
if (Pos != Console->LineSize)
LineInputEdit(Console, 1, 0, NULL);
return;
@@ -270,14 +270,14 @@
case VK_PRIOR:
{
- /* Recall first history entry */
+ /* Recall the first history entry */
LineInputRecallHistory(Console, ExeName, -((WORD)-1));
return;
}
case VK_NEXT:
{
- /* Recall last history entry */
+ /* Recall the last history entry */
LineInputRecallHistory(Console, ExeName, +((WORD)-1));
return;
}
@@ -286,8 +286,8 @@
case VK_F5:
{
/*
- * Recall previous history entry. On first time, actually recall the
- * current (usually last) entry; on subsequent times go back.
+ * Recall the previous history entry. On first time, actually recall
+ * the current (usually last) entry; on subsequent times go back.
*/
LineInputRecallHistory(Console, ExeName, Console->LineUpPressed ? -1 : 0);
Console->LineUpPressed = TRUE;
@@ -296,14 +296,14 @@
case VK_DOWN:
{
- /* Recall next history entry */
+ /* Recall the next history entry */
LineInputRecallHistory(Console, ExeName, +1);
return;
}
case VK_F3:
{
- /* Recall remainder of current history entry */
+ /* Recall the remainder of the current history entry */
HistoryGetCurrentEntry(Console, ExeName, &Entry);
if (Pos * sizeof(WCHAR) < Entry.Length)
{
@@ -356,7 +356,7 @@
PHISTORY_BUFFER Hist;
INT HistPos;
- /* Search for history entries starting with input. */
+ /* Search for history entries starting with input */
Hist = HistoryCurrentBuffer(Console, ExeName);
if (!Hist || Hist->NumEntries == 0) return;
@@ -403,10 +403,12 @@
* OK, we deal with normal keys, we can continue...
*/
- if (KeyEvent->uChar.UnicodeChar == L'\b' && GetConsoleInputBufferMode(Console) & ENABLE_PROCESSED_INPUT)
- {
- /* backspace handling - if processed input enabled then we handle it here
- * otherwise we treat it like a normal char. */
+ if (KeyEvent->uChar.UnicodeChar == L'\b' && (GetConsoleInputBufferMode(Console) & ENABLE_PROCESSED_INPUT))
+ {
+ /*
+ * Backspace handling - if processed input enabled then we handle it
+ * here, otherwise we treat it like a normal character.
+ */
if (Pos > 0)
{
LineInputSetPos(Console, Pos - 1);
@@ -415,9 +417,18 @@
}
else if (KeyEvent->uChar.UnicodeChar == L'\r')
{
- Entry.Length = Entry.MaximumLength = Console->LineSize * sizeof(WCHAR);
- Entry.Buffer = Console->LineBuffer;
- HistoryAddEntry(Console, ExeName, &Entry);
+ /*
+ * Only add a history entry if console echo is enabled. This ensures
+ * that anything sent to the console when echo is disabled (e.g.
+ * binary data, or secrets like passwords...) does not remain stored
+ * in memory.
+ */
+ if (GetConsoleInputBufferMode(Console) & ENABLE_ECHO_INPUT)
+ {
+ Entry.Length = Entry.MaximumLength = Console->LineSize * sizeof(WCHAR);
+ Entry.Buffer = Console->LineBuffer;
+ HistoryAddEntry(Console, ExeName, &Entry);
+ }
/* TODO: Expand aliases */
DPRINT1("TODO: Expand aliases\n");
@@ -434,10 +445,10 @@
/*
* Add \n if processed input. There should usually be room for it,
- * but an exception to the rule exists: the buffer could have been
+ * but an exception to the rule exists: the buffer could have been
* pre-filled with LineMaxSize - 1 characters.
*/
- if (GetConsoleInputBufferMode(Console) & ENABLE_PROCESSED_INPUT &&
+ if ((GetConsoleInputBufferMode(Console) & ENABLE_PROCESSED_INPUT) &&
Console->LineSize < Console->LineMaxSize)
{
Console->LineBuffer[Console->LineSize++] = L'\n';
Author: hbelusca
Date: Tue Jun 7 22:52:44 2016
New Revision: 71591
URL: http://svn.reactos.org/svn/reactos?rev=71591&view=rev
Log:
[CONSRV]
- Remove a wrong assertion that I introduced in r70281 concerning Console->LinePos.
- Fix some boundary conditions.
- Completely reset line discipline variables when the line buffer is freed.
- Fix a potential buffer overrun in the case ReadControl->nInitialChars was larger than Console->LineMaxSize (the size of Console->LineBuffer), which serves to initialize Console->LineSize, Console->LinePos, and copy nInitialChars characters from user buffer.
CORE-11380 CORE-10997 #resolve
Modified:
trunk/reactos/win32ss/user/winsrv/consrv/frontends/terminal.c
Modified: trunk/reactos/win32ss/user/winsrv/consrv/frontends/terminal.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/frontends/terminal.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/frontends/terminal.c [iso-8859-1] Tue Jun 7 22:52:44 2016
@@ -330,7 +330,13 @@
{
/* Start a new line */
Console->LineMaxSize = max(256, NumCharsToRead);
- ASSERT(ReadControl->nInitialChars <= Console->LineMaxSize);
+
+ /*
+ * Fixup ReadControl->nInitialChars in case the number of initial
+ * characters is bigger than the number of characters to be read.
+ * It will always be, lesser than or equal to Console->LineMaxSize.
+ */
+ ReadControl->nInitialChars = min(ReadControl->nInitialChars, NumCharsToRead);
Console->LineBuffer = ConsoleAllocHeap(0, Console->LineMaxSize * sizeof(WCHAR));
if (Console->LineBuffer == NULL) return STATUS_NO_MEMORY;
@@ -346,7 +352,7 @@
* worry about ANSI <-> Unicode conversion.
*/
memcpy(Console->LineBuffer, Buffer, Console->LineSize * sizeof(WCHAR));
- if (Console->LineSize == Console->LineMaxSize)
+ if (Console->LineSize >= Console->LineMaxSize)
{
Console->LineComplete = TRUE;
Console->LinePos = 0;
@@ -356,7 +362,7 @@
/* If we don't have a complete line yet, process the pending input */
while (!Console->LineComplete && !IsListEmpty(&InputBuffer->InputEvents))
{
- /* Remove input event from queue */
+ /* Remove an input event from the queue */
CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
if (IsListEmpty(&InputBuffer->InputEvents))
{
@@ -378,12 +384,14 @@
/* Check if we have a complete line to read from */
if (Console->LineComplete)
{
- // NOTE: I want to check whether we always set LinePos to zero
- // when LineComplete is set to TRUE.
- // Basically, we are going to use LinePos as 'i'.
- ASSERT(Console->LinePos == 0);
-
- while (i < NumCharsToRead && Console->LinePos != Console->LineSize)
+ /*
+ * Console->LinePos keeps the next position of the character to read
+ * in the line buffer across the different calls of the function,
+ * so that the line buffer can be read by chunks after all the input
+ * has been buffered.
+ */
+
+ while (i < NumCharsToRead && Console->LinePos < Console->LineSize)
{
WCHAR Char = Console->LineBuffer[Console->LinePos++];
@@ -398,11 +406,14 @@
++i;
}
- if (Console->LinePos == Console->LineSize)
- {
- /* Entire line has been read */
+ if (Console->LinePos >= Console->LineSize)
+ {
+ /* The entire line has been read */
ConsoleFreeHeap(Console->LineBuffer);
Console->LineBuffer = NULL;
+ Console->LinePos = Console->LineMaxSize = Console->LineSize = 0;
+ // Console->LineComplete = Console->LineUpPressed = FALSE;
+ Console->LineComplete = FALSE;
}
Status = STATUS_SUCCESS;
@@ -415,7 +426,7 @@
/* Character input */
while (i < NumCharsToRead && !IsListEmpty(&InputBuffer->InputEvents))
{
- /* Remove input event from queue */
+ /* Remove an input event from the queue */
CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
if (IsListEmpty(&InputBuffer->InputEvents))
{