Skip to content

Commit ff04aeb

Browse files
committed
fix: keep and redirect the opm render errors and remove security vulnerability for run_cmd
Signed-off-by: NiallTwomey2 <nialltwomey44@gmail.com>
1 parent c4968e9 commit ff04aeb

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎.rhdh/scripts/install-rhdh-catalog-source.sh‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,15 @@ function errorf() {
8383
# Run a command. At debug, stream it. Otherwise hide stdout/stderr,
8484
# and print the captured output only if the command fails.
8585
function run_cmd() {
86-
local out rc
86+
local out rc=0
8787
if [[ "${LOG_LEVEL}" == "debug" ]]; then
8888
"$@"
8989
return $?
9090
fi
9191
out="$(mktemp)"
92-
set +e
93-
"$@" >"${out}" 2>&1
94-
rc=$?
95-
set -e
92+
"$@" >"${out}" 2>&1 || rc=$?
9693
if [[ "${rc}" -ne 0 ]]; then
97-
errorf "Command failed (${rc}): $*"
94+
errorf "Command failed (${rc})"
9895
cat "${out}" >&2
9996
fi
10097
rm -f "${out}"
@@ -205,8 +202,6 @@ function resolve_olm_version() {
205202
fi
206203
}
207204

208-
209-
210205
function cleanup() {
211206
rm -fr "${TMPDIR}" || true
212207
jobs -p | xargs -r kill 2>/dev/null || true
@@ -319,11 +314,19 @@ function render_iib() {
319314

320315
mkdir -p "${TMPDIR}/rhdh/rhdh"
321316
debugf "Rendering IIB $UPSTREAM_IIB as a local file..."
317+
local render_err
318+
render_err="$(mktemp)"
322319
if [[ "${LOG_LEVEL}" == "debug" ]]; then
323320
opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml"
324321
else
325-
opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" 2>/dev/null
322+
if ! opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" 2>"${render_err}"; then
323+
errorf "opm render failed"
324+
cat "${render_err}" >&2
325+
rm -f "${render_err}"
326+
return 1
327+
fi
326328
fi
329+
rm -f "${render_err}"
327330
if [ ! -s "${TMPDIR}/rhdh/rhdh/render.yaml" ]; then
328331
errorf "
329332
[ERROR] 'opm render $UPSTREAM_IIB' returned an empty output, which likely means that this IIB Image does not contain any operators in it.

0 commit comments

Comments
 (0)