From 6f40c6686d5e94aa2cead2739f61a45c594a7d6a Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Wed, 21 Apr 2010 14:00:55 -0400 Subject: 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'erts/emulator/sys/unix/sys.c') diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c index 267f7d07aa..50b208848f 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]; } } -- cgit v1.2.3