From: Alex Henrie Subject: [PATCH] cmd: Ensure new volume label is null-terminated (Coverity) Message-Id: <20210827064438.143080-1-alexhenrie24@gmail.com> Date: Fri, 27 Aug 2021 00:44:38 -0600 The command `echo | wine cmd /k 'label c:'` causes WCMD_ReadFile to return the single character '\n' without a null terminator, which would then cause garbage to be written to ~/.wine/drive_c/.windows-label. Signed-off-by: Alex Henrie --- programs/cmd/builtins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index c7df724ae00..62ace7510a1 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -4716,8 +4716,8 @@ int WCMD_volume(BOOL set_label, const WCHAR *path) if (set_label) { WCMD_output (WCMD_LoadMessage(WCMD_VOLUMEPROMPT)); WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, ARRAY_SIZE(string), &count); + string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ if (count > 1) { - string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */ } if (*path) { -- 2.33.0