1
0

fix: avoid sed interpolation when prepending log summary

Use a temporary file to write the summary header and existing log content, then replace the original log atomically. This removes the dependency on sed for summary insertion and avoids unsafe string interpolation.
This commit is contained in:
2026-04-26 00:36:01 +02:00
parent 46f42c8893
commit 3fe7959850
2 changed files with 20 additions and 7 deletions
+18 -4
View File
@@ -10,7 +10,7 @@ showHelp() {
}
checkDependencies() {
local -a REQUIRED_CMDS=(ssh whiptail sed tee rm touch)
local -a REQUIRED_CMDS=(ssh whiptail cat tee rm touch)
local -a MISSING_CMDS=()
local CMD
@@ -84,6 +84,22 @@ runSSH() {
ssh "${SSH_USER}@${HOST}" "$@"
}
prependLogSummary() {
local SUMMARY_CONTENT="${1}"
local TEMP_LOGFILENAME="${LOGFILENAME}.tmp"
{
echo "Results :"
echo "---------"
echo ""
echo -e "${SUMMARY_CONTENT}"
echo ""
echo ""
cat "${LOGFILENAME}"
} > "${TEMP_LOGFILENAME}"
mv "${TEMP_LOGFILENAME}" "${LOGFILENAME}"
}
selectNodes(){
local -a OPTIONS=()
local -a SELECTED_ITEMS=()
@@ -152,9 +168,7 @@ selectNodes(){
done
done
sed -i "1s/^/${RESULT//\//\\\/}\n\n\n\n/" "${LOGFILENAME}"
sed -i "1s/^/---------\n\n/" "${LOGFILENAME}"
sed -i "1s/^/Results :\n/" "${LOGFILENAME}"
prependLogSummary "${RESULT}"
if [ -n "${LOGVIEWER}" ]; then
"${LOGVIEWER}" "${LOGFILENAME}"
else