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/win32/sys_env.c') 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