Skip to content

Commit

Permalink
Optionally disallow empty environment values again
Browse files Browse the repository at this point in the history
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
d6b1ac7 (* 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 <[email protected]>
  • Loading branch information
dscho authored and lazka committed Aug 18, 2023
1 parent 18541ea commit a02572d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion winsup/cygwin/environ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static char **lastenviron;
/* Parse CYGWIN options */

static NO_COPY bool export_settings = false;
static bool emptyenvvalues = true;

enum settings
{
Expand Down Expand Up @@ -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}}}
};

Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit a02572d

Please sign in to comment.