From a02572d52a505393a849dca701b6984c30d523d4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 6 Sep 2022 10:40:58 +0200 Subject: [PATCH] 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 --- 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 0152095875..a1abbb5e7d 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 { @@ -130,6 +131,7 @@ static struct parse_thing {"enable_pcon", {&disable_pcon}, setnegbool, NULL, {{true}, {false}}}, {"winjitdebug", {&winjitdebug}, setbool, NULL, {{false}, {true}}}, {"nativeinnerlinks", {&nativeinnerlinks}, setbool, NULL, {{false}, {true}}}, + {"emptyenvvalues", {&emptyenvvalues}, setbool, NULL, {{false}, {true}}}, {NULL, {0}, setdword, 0, {{0}, {0}}} }; @@ -1325,7 +1327,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. */