From 5e8893f2f6b259a26ed5bfb7e3b4ea4580145445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delanoy?= Date: Sat, 1 Oct 2011 13:43:18 +0200 Subject: [PATCH] cmd: Handle truncation for console reads. --- programs/cmd/batch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index 52dd08eac6..5f83c355df 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -199,7 +199,12 @@ WCHAR *WCMD_fgets(WCHAR *s, int noChars, HANDLE h, BOOL is_console_handle) if (is_console_handle) { status = ReadConsoleW(h, s, noChars, &charsRead, NULL); if (!status) return NULL; - s[charsRead-2] = '\0'; /* Strip \r\n */ + if (s[charsRead-2] == '\r') + s[charsRead-2] = '\0'; /* Strip \r\n */ + else { + /* Truncate */ + s[noChars-1] = '\0'; + } return p; }