From 0a6db8663b5558c152a351075bff296733bd3a0d Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Wed, 21 Apr 2010 14:00:55 -0400 Subject: [PATCH] allow open_port to set env vars containing a trailing '=' character The erlang:open_port spawn and spawn_executable directives can include an {env, Env} directive to set up environment variables for the spawned process. A bug in ert/emulator/sys/unix/sys.c prevented applications from using {env, Env} to set an environment variable whose value ended with a '=' (equal sign) character; the code mistook the trailing equal sign as an indication that an environment variable was to be cleared from the environment of the spawned process. For example, passing an {env, Env} of {env, [{"foo", "bar="}]} would result in the code in sys.c seeing a string of the form "foo=bar=" The code would see the final '=' character and assume the directive wanted to clear a variable named "foo=bar" from the environment of the spawned process, rather than seeing it as a directive to set the environment variable "foo" to the value "bar=". Fix this problem and add a new regression test for it to the port test suite. --- erts/emulator/sys/unix/sys.c | 3 ++- erts/emulator/test/port_SUITE.erl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c index 31ab5d03de67..b7ab552530e1 100644 --- a/erts/emulator/sys/unix/sys.c +++ b/erts/emulator/sys/unix/sys.c @@ -1325,7 +1325,8 @@ static char **build_unix_environment(char *block) } for (j = 0; j < i; j++) { - if (cpp[j][strlen(cpp[j])-1] == '=') { + size_t last = strlen(cpp[j])-1; + if (cpp[j][last] == '=' && strchr(cpp[j], '=') == cpp[j]+last) { cpp[j] = cpp[--len]; } } diff --git a/erts/emulator/test/port_SUITE.erl b/erts/emulator/test/port_SUITE.erl index b9100738e46b..eb69bf917b86 100644 --- a/erts/emulator/test/port_SUITE.erl +++ b/erts/emulator/test/port_SUITE.erl @@ -881,6 +881,7 @@ env2(Config) -> ?line env_slave(Temp, [{"must_define_something","some_value"}, {"certainly_not_existing",false}, + {"ends_with_equal", "value="}, {Long,false}, {"glurf","a glorfy string"}]),