Skip to content

Commit

Permalink
Distributed: fix syntax check of environment variable names (#38577)
Browse files Browse the repository at this point in the history
- previous code accidentally checked `ENV` instead of `env`

- now separate `env` checks for POSIX shell and `cmd.exe`, which have
  quite different format constraints for their environment variable names
  • Loading branch information
mgkuhn committed Nov 26, 2020
1 parent c43c07f commit 03c7d6c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stdlib/Distributed/src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ function launch_on_machine(manager::SSHManager, machine::AbstractString, cnt, pa
env[var] = ENV[var]
end
end
for var in keys(ENV)
occursin(r"^[a-zA-Z0-9_]+$", var) || throw(ArgumentError(var))
end

# Julia process with passed in command line flag arguments
if shell == :posix
Expand All @@ -269,6 +266,8 @@ function launch_on_machine(manager::SSHManager, machine::AbstractString, cnt, pa
cmds = "$(shell_escape_posixly(exename)) $(shell_escape_posixly(exeflags))"
# set environment variables
for (var, val) in env
occursin(r"^[a-zA-Z_][a-zA-Z_0-9]*\z", var) ||
throw(ArgumentError("invalid env key $var"))
cmds = "export $(var)=$(shell_escape_posixly(val))\n$cmds"
end
# change working directory
Expand All @@ -290,6 +289,7 @@ function launch_on_machine(manager::SSHManager, machine::AbstractString, cnt, pa
end
# set environment variables
for (var, val) in env
occursin(r"^[a-zA-Z0-9_()[\]{}\$\\/#',;\.@!?*+-]+\z", var) || throw(ArgumentError("invalid env key $var"))
remotecmd = "set $(var)=$(shell_escape_wincmd(val))&& $remotecmd"
end

Expand Down

0 comments on commit 03c7d6c

Please sign in to comment.