Skip to content

Commit 4bc902f

Browse files
committed
fix: harden WORK_HOME path matching in make issue
Address review: - generate-vars.sh: require a path boundary after WORK_HOME so a prefix (e.g. /tmp/work) does not corrupt sibling paths (e.g. /tmp/work_other) - makeIssue.sh: tolerate trailing slash in WORK_HOME and slash runs in tar member names (${WORK_HOME}/x yields ws//x when WORK_HOME ends in /) Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
1 parent 7b6f366 commit 4bc902f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

flow/util/generate-vars.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ while read -r VAR; do
6060
# symlink-resolved form may appear in values. Skip when WORK_HOME is
6161
# FLOW_HOME, which is handled via ${FLOW_HOME} below.
6262
for work_path in "${WORK_HOME:-.}" "${WORK_ROOT}"; do
63+
work_path="${work_path%/}"
6364
if [[ "${work_path}" == /* && "${work_path}" != "${FLOW_ROOT}" ]]; then
64-
value=$(sed -e "s,\(^\|[: \"']\)${work_path},\1.,g" <<< "${value}")
65+
# require a path boundary after the match so e.g. /tmp/work
66+
# does not corrupt /tmp/work_other
67+
value=$(sed -e "s,\(^\|[: \"']\)${work_path}\(/\|[: \"']\|$\),\1.\2,g" <<< "${value}")
6568
fi
6669
done
6770
for path in workspace platforms; do

flow/util/makeIssue.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ fi
132132
# the tarball root instead of recreating the absolute path (e.g. tmp/...).
133133
# Both the literal and the symlink-resolved form may appear in member names.
134134
WORK_ROOT=$(realpath "${WORK_HOME:-.}")
135-
WORK_HOME_TRANSFORMS=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_ROOT}/|${ISSUE_TARGET}_${ISSUE_TAG}/|S")
136-
if [[ "${WORK_HOME:-.}" == /* && "${WORK_HOME:-.}" != "${WORK_ROOT}" ]]; then
137-
WORK_HOME_TRANSFORMS+=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_HOME}/|${ISSUE_TARGET}_${ISSUE_TAG}/|S")
135+
WORK_HOME_TRANSFORMS=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_ROOT}//*|${ISSUE_TARGET}_${ISSUE_TAG}/|S")
136+
if [[ "${WORK_HOME:-.}" == /* && "${WORK_HOME%/}" != "${WORK_ROOT}" ]]; then
137+
WORK_HOME_TRANSFORMS+=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_HOME%/}//*|${ISSUE_TARGET}_${ISSUE_TAG}/|S")
138138
fi
139139
tar --use-compress-program=${COMPRESS} \
140140
--ignore-failed-read -chf ${TAR_NAME} \

0 commit comments

Comments
 (0)