Fix replace-conf-from-env.sh word-splitting env values into junk config lines - #18680
Open
anishmehta24 wants to merge 1 commit into
Open
anishmehta24 wants to merge 1 commit into
anishmehta24 wants to merge 1 commit into
Conversation
…ig lines `replace_configs` iterated over the unquoted output of `env`, so any variable whose value contains whitespace (JAVA_TOOL_OPTIONS, a multi-word SOME_VAR, ...) was split into words, and every lowercase word was appended to iotdb-system.properties as its own line. The junk also shifted the line numbers the sed edits rely on, and `_=/usr/bin/env` from bash slipped through the intended `_` filter. Iterate over exported variable names (`compgen -e`) and read each value through indirection instead, quote the paths and values passed to process_single, and replace an existing key with `sed Nc` rather than delete + append: the latter silently dropped the override when the key was on the last line of the file. Closes apache#18655
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
docker/src/main/DockerCompose/replace-conf-from-env.shiterated over the unquoted output ofenv(for v in $(env)), so any variable whose value contains whitespace was split into words and every lowercase word was appended toiotdb-system.propertiesas its own line. With the reporter's-e "SOME_VAR=this is a multi word value"the file ended with(
_=/usr/bin/envcame from bash's$_, which the! 2w$key_name =~ ^_test never actually filtered). The junk lines also shift the line numbers thesededits rely on.While reproducing it I hit a second, independent loss: when the key being overridden sits on the last line of the file,
sed -i "${line_no}d"followed bysed -i "${line_no}a..."addresses a line that no longer exists, so the override is silently dropped (dn_rpc_port=7777disappeared entirely in the repro below).Changes:
replace_configsiterates over exported variable names (compgen -e) and reads each value through${!key_name}, so values are never word-split. A value containing a newline is skipped with a message rather than corrupting the file. Names starting with_are skipped as intended.key=valuepairs are quoted on the way intoprocess_single; the key is taken with${key_value%%=*}.sed Nc; a commented one still gets the override appended after it; a missing key is appended withsed $a.Verification
Ran the old and the new script against a 4-line properties file with
IOTDB_HOMEpointing at a temp dir andSOME_VAR="this is a multi word value" JAVA_TOOL_OPTIONS="-Xms1g -Xmx2g" dn_rpc_address=0.0.0.0 dn_rpc_port=7777 dn_new_key="a b c"in the environment.Before:
(
dn_rpc_port=6667is gone and7777never landed.)After:
bash -npasses; the script only uses bash builtins plusgrep/cut/sedas before, so no new image dependency.Closes #18655
🤖 Generated with Claude Code