Skip to content

Commit

Permalink
allow open_port to set env vars containing a trailing '=' character
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vinoski committed Apr 21, 2010
1 parent 8d1088d commit 0a6db86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion erts/emulator/sys/unix/sys.c
Expand Up @@ -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];
}
}
Expand Down
1 change: 1 addition & 0 deletions erts/emulator/test/port_SUITE.erl
Expand Up @@ -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"}]),

Expand Down

0 comments on commit 0a6db86

Please sign in to comment.