krnl386.exe16-Invalid_Console_Handles: Remove patch set.

Despite Michael Müller's claim that all patches in wine-staging actually fix
something [1], I've come across several patch sets over the years that seem to
be related to some contemporaneous work but don't actually fix any application
themselves (e.g. wine-staging commits 5d8901ac21, ba9a7a6a74, probably most of
e353590528; I think there are plenty of other examples as well.)

This patch appears to fall into this category. The upstream commit it was
written in response to was bc68b30d20.

The application in question is buggy. It uses OpenFile(), but compares the
return value to 0 instead of -1. The open in question is the first in the
program's run. The problem occurs if the DOS handles are unassigned, in which
case the valid handle 0 will be returned, and the program will interpret it as
failure, hit some broken code path, and crash.

bc68b30d20 fixes this by ensuring that the DOS standard handles are always
valid, and therefore OpenFile() will always return at least 5. This seems to
match what happens on Windows. I can reproduce this fix; I didn't go to the
trouble of building its parent, but reverting that patch in current Wine does
make the program crash the exact same way (comparing to the +relay log helpfully
provided in the bug report).

Sebastian probably saw this commit, thought that "well, there's multiple ways
for a handle to be invalid", wrote this patch catching the additional ones, and
for some reason never submitted it upstream.

Thing is, these handles come from the server, and they're guaranteed to be
either valid or zero. As evidence cf. the duplicate_handle() calls in the
new_process request handler, which were present even at the time. Hence this
patch isn't doing anything, so remove it.

[1] https://www.winehq.org/mailman3/hyperkitty/list/wine-devel@winehq.org/message/YGKVQN2N537MXAVSMLHX5IV4XCEWKBVY/
This commit is contained in:
Zebediah Figura 2023-12-26 19:56:24 -06:00
parent 0525ea8268
commit 2ec2518486
2 changed files with 0 additions and 71 deletions

View File

@ -1,70 +0,0 @@
From 190e36c5ea8047e42b10d8c626bb221b4f3d5b02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Fri, 26 Feb 2016 21:35:52 +0100
Subject: krnl386.exe16: Really translate all invalid console handles into
usable DOS handles.
---
dlls/krnl386.exe16/file.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/dlls/krnl386.exe16/file.c b/dlls/krnl386.exe16/file.c
index b66b753..e6b1233 100644
--- a/dlls/krnl386.exe16/file.c
+++ b/dlls/krnl386.exe16/file.c
@@ -45,6 +45,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(file);
static HANDLE dos_handles[DOS_TABLE_SIZE];
+static void set_standard_handle(HANDLE *out, HANDLE null, HANDLE in)
+{
+ if (!in || in == INVALID_HANDLE_VALUE ||
+ !DuplicateHandle(GetCurrentProcess(), in, GetCurrentProcess(),
+ out, 0, TRUE, DUPLICATE_SAME_ACCESS))
+ {
+ DuplicateHandle(GetCurrentProcess(), null, GetCurrentProcess(),
+ out, 0, TRUE, DUPLICATE_SAME_ACCESS);
+ }
+}
+
/***********************************************************************
* FILE_InitProcessDosHandles
*
@@ -53,25 +64,21 @@ static HANDLE dos_handles[DOS_TABLE_SIZE];
*/
static void FILE_InitProcessDosHandles( void )
{
- HANDLE hStdInput, hStdOutput, hStdError, hNull;
+ HANDLE hNull;
static BOOL init_done /* = FALSE */;
- HANDLE cp = GetCurrentProcess();
if (init_done) return;
init_done = TRUE;
- hStdInput = GetStdHandle(STD_INPUT_HANDLE);
- hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- hStdError = GetStdHandle(STD_ERROR_HANDLE);
+
hNull = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+
/* Invalid console handles need to translate to real DOS handles in a new process */
- if (!hStdInput) hStdInput = hNull;
- if (!hStdOutput) hStdOutput = hNull;
- if (!hStdError) hStdError = hNull;
- DuplicateHandle(cp, hStdInput, cp, &dos_handles[0], 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(cp, hStdOutput, cp, &dos_handles[1], 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(cp, hStdError, cp, &dos_handles[2], 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(cp, hStdError, cp, &dos_handles[3], 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(cp, hStdError, cp, &dos_handles[4], 0, TRUE, DUPLICATE_SAME_ACCESS);
+ set_standard_handle(&dos_handles[0], hNull, GetStdHandle(STD_INPUT_HANDLE));
+ set_standard_handle(&dos_handles[1], hNull, GetStdHandle(STD_OUTPUT_HANDLE));
+ set_standard_handle(&dos_handles[2], hNull, GetStdHandle(STD_ERROR_HANDLE));
+ set_standard_handle(&dos_handles[3], hNull, GetStdHandle(STD_ERROR_HANDLE));
+ set_standard_handle(&dos_handles[4], hNull, GetStdHandle(STD_ERROR_HANDLE));
+
CloseHandle(hNull);
}
--
2.7.1

View File

@ -1 +0,0 @@
Fixes: [7106] Translate all invalid console handles into usable DOS handles