[BUG] WINDOWS32: $(shell) deadlocks when command contains literal " inside single quotes
张 天夫 <[email protected]> Sat, 4 Apr 2026 06:35:47 +0000
| Newsgroups | gmane.comp.gnu.make.bugs |
|---|---|
| Message-ID | <CYXP222MB089835E7705FDB1B7D7C9EE9C85FA@CYXP222MB0898.NAMP222.PROD.OUTLOOK.COM> |
--_000_CYXP222MB089835E7705FDB1B7D7C9EE9C85FACYXP222MB0898NAMP_
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: base64
SSBmb3VuZCBhIFdpbmRvd3MzMiBpc3N1ZSBpbiAkKHNoZWxsKTogd2l0aCBhbiBNU1lTMi9DeWd3
aW4gYmluYXJ5LCBhIGxpdGVyYWwgIiBpbnNpZGUgc2luZ2xlIHF1b3RlcyBjYW4gZGVhZGxvY2sg
bWFrZS4NCg0KTWluaW1hbCByZXByb2R1Y2VyOg0KDQogIF8gOj0gJChzaGVsbCBncmVwICciJyBN
YWtlZmlsZSkNCg0KV2l0aCBHTlUgTWFrZSA0LjQuMSAoZXp3aW5wb3J0cywgQnVpbHQgZm9yIFdp
bmRvd3MzMiksIFNIRUxMIHNldCB0byBHaXQtZm9yLVdpbmRvd3Mgc2guZXhlLCBhbmQgZ3JlcCBm
cm9tIEdpdC1mb3ItV2luZG93cy9NU1lTMiwgcnVubmluZyBtYWtlIGhhbmdzIGluZGVmaW5pdGVs
eS4NCg0KVGhpcyBzaG91bGQgYmUgYSB0cml2aWFsIHNlbGYtc2VhcmNoLCBidXQgZ3JlcCBuZXZl
ciByZWNlaXZlcyB0aGUgZmlsZSBhcmd1bWVudCBhbmQgd2FpdHMgb24gc3RkaW4gaW5zdGVhZC4N
Cg0KVGhlIGFwcGFyZW50IGNhdXNlIGlzOg0KDQoxLiBjb25zdHJ1Y3RfY29tbWFuZF9hcmd2X2lu
dGVybmFsKCkgdGFrZXMNCiAgICBncmVwICciJyBNYWtlZmlsZQ0KICBvbiB0aGUgZmFzdCBwYXRo
IGFuZCBidWlsZHMgYXJnd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ZSBGU0YgQ29weXJpZ2h0IEFzc2lnbm1lbnQgZm9yIHRoaXMgb25lLXRpbWUgY29udHJpYnV0
aW9uLiBUaGUgZGlmZiBhYm92ZSBpcyBvbmx5IGEgc3VnZ2VzdGVkIGZpeCBkaXJlY3Rpb247IHBs
ZWFzZSBmZWVsIGZyZWUgdG8gcmVpbXBsZW1lbnQgaXQgaW5kZXBlbmRlbnRseSBpZiB5b3UgYWdy
ZWUgd2l0aCB0aGUgYXBwcm9hY2guDQo=
--_000_CYXP222MB089835E7705FDB1B7D7C9EE9C85FACYXP222MB0898NAMP_
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dgb2312">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
I found a Windows32 issue in $(shell): with an MSYS2/Cygwin binary, a liter=
al " inside single quotes can deadlock make.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Minimal reproducer:</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
_ :=3D $(shell grep '"' Makefile)</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
With GNU Make 4.4.1 (ezwinports, Built for Windows32), SHELL set to Git-for=
-Windows sh.exe, and grep from Git-for-Windows/MSYS2, running make hangs in=
definitely.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
This should be a trivial self-search, but grep never receives the file argu=
ment and waits on stdin instead.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
The apparent cause is:</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
1. construct_command_argv_internal() takes</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
grep '"' Makefile</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
on the fast path and builds argv =3D {"grep", "\"=
;", "Makefile"}.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
2. make_command_line() then prepares a CreateProcess command line using MSV=
CRT quoting rules, so the literal " becomes \".</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
3. MSYS2/Cygwin programs do not parse CreateProcess command lines with MSVC=
RT rules; they treat \" as a backslash plus the start of a quoted stri=
ng, so the file path is absorbed into the previous argument.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
At that point grep sees no file operands, falls back to stdin, and the pipe=
deadlocks.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
This looks like a design limitation in the Windows fast path: it assumes MS=
VCRT-compatible argv parsing, but that assumption is false for a significan=
t class of Windows executables.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Suggested fix: on WINDOWS32, if the fast path sees a literal " inside =
a single-quoted string, fall back to the slow path and invoke via $(SHELL).=
That should be low-cost and avoids the runtime-specific quoting mismatch.<=
/div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Suggested diff below. I wrote it from source reading rather than from a loc=
al clone; the context in src/job.c should still be unique.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
--- a/src/job.c</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
+++ b/src/job.c</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
@@ in construct_command_argv_internal(), inside the if (instring) block @@<=
/div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
else if (instring =3D=3D '"' =
&& strncmp (p, "\\\"", 2) =3D=3D 0)</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
*ap++ =3D *++p;</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
#endif</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
+#ifdef WINDOWS32</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
+ else if (instring =3D=3D '\'' &&=
; *p =3D=3D '"')</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
+ goto slow;</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
+#endif</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
else</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
*ap++ =3D *p;</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
}</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Environment:</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Make: GNU Make 4.4.1, Built for Windows32 (ezwinports)</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Shell: Git-for-Windows sh.exe</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
grep: Git-for-Windows grep.exe (msys-2.0.dll)</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
OS: Windows 10/11</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
I am not planning to sign the FSF Copyright Assignment for this one-time co=
ntribution. The diff above is only a suggested fix direction; please feel f=
ree to reimplement it independently if you agree with the approach.</div>
</body>
</html>
--_000_CYXP222MB089835E7705FDB1B7D7C9EE9C85FACYXP222MB0898NAMP_--