From 6925a0da3cf0fd299e5e468fd95c4d0a697b86ae Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 7 Jun 2010 16:33:14 +0200 Subject: allow open_port with env vars with trailing '=' on Windows Same problem that Steve Vinoski fixed for Unix. Similar fix done in erts/emulator/sys/win32/sys_env.c for Windows. Copy-paste from his commit-message: 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=". --- erts/emulator/sys/win32/sys_env.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'erts/emulator/sys') diff --git a/erts/emulator/sys/win32/sys_env.c b/erts/emulator/sys/win32/sys_env.c index ac4be3f316..ecfe4d5ba3 100644 --- a/erts/emulator/sys/win32/sys_env.c +++ b/erts/emulator/sys/win32/sys_env.c @@ -145,15 +145,17 @@ merge_environment(char *old, char *add) for(j = 0; a_arg[j] != NULL; ++j){ char **tmp; char *current = a_arg[j]; + char *eq_p = strchr(current,'='); + int unset = (eq_p!=NULL && eq_p[1]=='\0'); if ((tmp = find_arg(c_arg, current)) != NULL) { - if (current[strlen(current)-1] != '=') { + if (!unset) { *tmp = current; } else { *tmp = c_arg[--i]; c_arg[i] = NULL; } - } else if (current[strlen(current)-1] != '=') { + } else if (!unset) { c_arg[i++] = current; c_arg[i] = NULL; } -- cgit v1.2.3 From 65ccc309a0225863913d991f56f17e2aa4f85266 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 7 Jun 2010 16:42:40 +0200 Subject: fix open_port with many unset env vars The erlang:open_port spawn and spawn_executable directives can include an {env, Env} directive to set up environment variables for the spawned process. Variables can be unset with {"NameOfVariable",false}. A bug in ert/emulator/sys/unix/sys.c could cause unset variables to not be unset. This would typically happen if there where more variables to be unset than there where already set variables in the destination evironment. Fix this problem for unix and add a new regression test for it to the port test suite. Windows does not seem to have the same problem. --- erts/emulator/sys/unix/sys.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'erts/emulator/sys') diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c index 151fa06e8e..737ffd9f94 100644 --- a/erts/emulator/sys/unix/sys.c +++ b/erts/emulator/sys/unix/sys.c @@ -1328,10 +1328,18 @@ static char **build_unix_environment(char *block) } } - for (j = 0; j < i; j++) { + for (j = 0; j < i; ) { size_t last = strlen(cpp[j])-1; if (cpp[j][last] == '=' && strchr(cpp[j], '=') == cpp[j]+last) { cpp[j] = cpp[--len]; + if (len < i) { + i--; + } else { + j++; + } + } + else { + j++; } } -- cgit v1.2.3