From 20792b9388aba40e39e11df9e1d4a9f3dbff6fcd Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 1 Nov 2025 13:11:40 -0700 Subject: Always read the stdin preamble in wixnative When the wixnative.exe exits before the C# code sends the preamble, we'll get an exception that the stdin pipe is already closed. Turns out some commands did not wait for the preamble, so make them all wait to remove the race condition. --- src/wix/wixnative/certhashes.cpp | 3 --- src/wix/wixnative/precomp.h | 1 - src/wix/wixnative/smartcab.cpp | 3 --- src/wix/wixnative/wixnative.cpp | 14 ++++++++++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/wix/wixnative/certhashes.cpp b/src/wix/wixnative/certhashes.cpp index cbb548ba..03ae4b5b 100644 --- a/src/wix/wixnative/certhashes.cpp +++ b/src/wix/wixnative/certhashes.cpp @@ -27,9 +27,6 @@ HRESULT CertificateHashesCommand( LPWSTR sczPublicKeyIdentifier = NULL; LPWSTR sczThumbprint = NULL; - hr = WixNativeReadStdinPreamble(); - ExitOnFailure(hr, "Failed to read stdin preamble before reading paths to get certificate hashes"); - // Get the hash for each provided file. for (;;) { diff --git a/src/wix/wixnative/precomp.h b/src/wix/wixnative/precomp.h index bc59d693..54af38e3 100644 --- a/src/wix/wixnative/precomp.h +++ b/src/wix/wixnative/precomp.h @@ -17,7 +17,6 @@ #include "cabcutil.h" #include "cabutil.h" -HRESULT WixNativeReadStdinPreamble(); HRESULT CertificateHashesCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]); HRESULT SmartCabCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]); HRESULT EnumCabCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]); diff --git a/src/wix/wixnative/smartcab.cpp b/src/wix/wixnative/smartcab.cpp index 1b925d42..ebe92c21 100644 --- a/src/wix/wixnative/smartcab.cpp +++ b/src/wix/wixnative/smartcab.cpp @@ -69,9 +69,6 @@ HRESULT SmartCabCommand( if (uiFileCount > 0) { - hr = WixNativeReadStdinPreamble(); - ExitOnFailure(hr, "failed to read stdin preamble before smartcabbing"); - hr = CompressFiles(hCab, &sczFirstFileToken); ExitOnFailure(hr, "failed to compress files into cabinet: %ls", sczCabPath); diff --git a/src/wix/wixnative/wixnative.cpp b/src/wix/wixnative/wixnative.cpp index 7a689fc3..d7db20f6 100644 --- a/src/wix/wixnative/wixnative.cpp +++ b/src/wix/wixnative/wixnative.cpp @@ -2,6 +2,9 @@ #include "precomp.h" +static HRESULT WixNativeReadStdinPreamble(); + + int __cdecl wmain(int argc, LPWSTR argv[]) { HRESULT hr = E_INVALIDARG; @@ -11,8 +14,14 @@ int __cdecl wmain(int argc, LPWSTR argv[]) if (argc < 2) { ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Must specify a command"); + + ExitFunction(); } - else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"smartcab", -1)) + + hr = WixNativeReadStdinPreamble(); + ExitOnFailure(hr, "failed to read stdin preamble"); + + if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"smartcab", -1)) { hr = SmartCabCommand(argc - 2, argv + 2); } @@ -33,11 +42,12 @@ int __cdecl wmain(int argc, LPWSTR argv[]) ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Unknown command: %ls", argv[1]); } +LExit: ConsoleUninitialize(); return HRESULT_CODE(hr); } -HRESULT WixNativeReadStdinPreamble() +static HRESULT WixNativeReadStdinPreamble() { HRESULT hr = S_OK; LPWSTR sczLine = NULL; -- cgit v1.2.3-55-g6feb