MSYS2-packages/msys2-runtime-3.5/0035-Optionally-disallow-empty-environment-values-again.patch
2025-04-10 10:05:41 +02:00

58 lines
2.3 KiB
Diff

From ba92e6b6f47d363e7919b698f603a4202cc41898 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Tue, 6 Sep 2022 10:40:58 +0200
Subject: [PATCH 35/N] Optionally disallow empty environment values again
We just disabled the code that skips environment variables whose values
are empty.
However, this code was introduced a long time ago into Cygwin in
d6b1ac7faa (* environ.cc (build_env): Don't put an empty environment
variable into the environment. Optimize use of "len". * errno.cc
(ERROR_MORE_DATA): Translate to EMSGSIZE rather than EAGAIN.,
2006-09-07), seemingly without any complaints.
Meaning: There might very well be use cases out there where it makes
sense to skip empty-valued environment variables.
Therefore, it seems like a good idea to have a "knob" to turn it back
on. With this commit, we introduce such a knob: by setting
`noemptyenvvalues` the `MSYS` variable (or appending it if that variable
is already set), users can tell the MSYS2 runtime to behave just like in
the olden times.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/environ.cc | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 6b385cd..12b4d57 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -36,6 +36,7 @@ static char **lastenviron;
/* Parse CYGWIN options */
static NO_COPY bool export_settings = false;
+static bool emptyenvvalues = true;
enum settings
{
@@ -119,6 +120,7 @@ static struct parse_thing
} known[] NO_COPY =
{
{"disable_pcon", {&disable_pcon}, setbool, NULL, {{false}, {true}}},
+ {"emptyenvvalues", {&emptyenvvalues}, setbool, NULL, {{false}, {true}}},
{"enable_pcon", {&disable_pcon}, setnegbool, NULL, {{true}, {false}}},
{"error_start", {func: error_start_init}, isfunc, NULL, {{0}, {0}}},
{"export", {&export_settings}, setbool, NULL, {{false}, {true}}},
@@ -1326,7 +1328,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
Note that this doesn't stop invalid strings without '=' in it
etc., but we're opting for speed here for now. Adding complete
checking would be pretty expensive. */
- if (len == 1)
+ if (len == 1 || (!emptyenvvalues && !*rest))
continue;
/* See if this entry requires posix->win32 conversion. */