Skip to content

Commit 570ffdc

Browse files
Set IFS to default before use in compiler. (#734)
* Fix: when compiler uses IFS, set it to default Signed-off-by: Bolun Thompson <[email protected]> * fix: remove local path from test Signed-off-by: Bolun Thompson <[email protected]> --------- Signed-off-by: Bolun Thompson <[email protected]> Co-authored-by: Bolun Thompson <[email protected]>
1 parent d5a3b13 commit 570ffdc

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

compiler/orchestrator_runtime/pash_prepare_call_compiler.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ else
4949
pash_runtime_return_code=1
5050
fi
5151

52+
# save IFS to restore after field splitting
53+
[ -n "${IFS+x}" ] && saved_IFS=$IFS
54+
unset IFS
5255
# Get assigned process id
5356
# We need to split the daemon response into elements of an array by
5457
# shell's field splitting.
5558
# shellcheck disable=SC2206
5659
response_args=($daemon_response)
5760
process_id=${response_args[1]}
5861

62+
[ -n "${saved_IFS+x}" ] && IFS="$saved_IFS"
63+
5964
pash_redir_output echo "$$: (2) Compiler exited with code: $pash_runtime_return_code"
6065

6166
## only when --assert_all_regions_parallellizable is used do we care about all regions being parallelizable

compiler/orchestrator_runtime/speculative/speculative_runtime.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ daemon_response=$(pash_spec_communicate_scheduler "$msg") # Blocking step, daemo
2626

2727
## Receive an exit code
2828
if [[ "$daemon_response" == *"OK:"* ]]; then
29+
# save IFS to restore after field splitting
30+
[ -n "${IFS+set}" ] && saved_IFS=$IFS
31+
unset IFS
2932
# shellcheck disable=SC2206
3033
response_args=($daemon_response)
34+
[ -n "${saved_IFS+set}" ] && IFS=$saved_IFS
3135
pash_redir_output echo "$$: (2) Scheduler responded: $daemon_response"
3236
cmd_exit_code=${response_args[1]}
3337
output_variable_file=${response_args[2]}
@@ -46,10 +50,8 @@ elif [[ "$daemon_response" == *"UNSAFE:"* ]]; then
4650
## KK 2023-06-01 Does `eval` work in general? We need to be precise
4751
## about which commands are unsafe to determine how to execute them.
4852
cmd=$(cat "$PASH_SPEC_NODE_DIRECTORY/$pash_speculative_command_id")
49-
## KK 2023-06-01 Not sure if this shellcheck warning must be resolved:
50-
## > note: Double quote to prevent globbing and word splitting.
51-
# shellcheck disable=SC2086
52-
eval $cmd
53+
## Word splitting isn't needed since eval combines all the arguments into a single string
54+
eval "$cmd"
5355
cmd_exit_code=$?
5456
elif [ -z "$daemon_response" ]; then
5557
## Trouble... Daemon crashed, rip

evaluation/tests/interface_tests/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ test_redir_dup()
321321
$shell redir-dup.sh
322322
}
323323

324+
test_IFS()
325+
{
326+
local shell=$1
327+
$shell test-IFS.sh
328+
}
329+
324330
## We run all tests composed with && to exit on the first that fails
325331
if [ "$#" -eq 0 ]; then
326332
run_test test1
@@ -365,6 +371,7 @@ if [ "$#" -eq 0 ]; then
365371
run_test test_star
366372
run_test test_env_vars
367373
run_test test_redir_dup
374+
run_test test_IFS
368375
else
369376
for testname in $@
370377
do
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
IFS=/
2+
curr_dir=/test1/test2/test3/test4
3+
for name in $curr_dir; do
4+
echo "$name"
5+
done

runtime/wait_for_output_and_sigpipe_rest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export internal_exec_status=$?
1515
# This value may contains multiple pids as a whitespace-separated string, and
1616
# we must split it as multiple pids by shell's field splitting.
1717
# shellcheck disable=SC2086
18-
(> /dev/null 2>&1 kill -SIGPIPE $pids_to_kill || true)
18+
(unset IFS; > /dev/null 2>&1 kill -SIGPIPE $pids_to_kill || true)
1919

2020
##
2121
## Old way of waiting, very inefficient.

0 commit comments

Comments
 (0)