Use mktemp_safe for temporary file generation

Replaced mktemp with mktemp_safe for safer temporary file creation.
This commit is contained in:
Alexandre
2026-01-09 09:25:23 +01:00
committed by GitHub
parent 2dd05df4c9
commit 7f56374ec1

View File

@@ -20,6 +20,16 @@ if [[ ! -f "$ENV_FILE" ]]; then
printf '# Generated by 00-global_var.sh from %s\n' "$JSONSOURCE" > "$ENV_FILE"
fi
# mktemp
mktemp_safe() {
local tmpdir="${TMPDIR:-/tmp}"
mkdir -p "$tmpdir" || return 1
local tmpfile
tmpfile="$(mktemp "$tmpdir/tmp.XXXXXXXXXX")" || return 1
printf '%s\n' "$tmpfile"
}
# Define secrets location (optional)
SECRETSOURCE=""
if [[ -f /homeassistant/secrets.yaml ]]; then
@@ -32,7 +42,7 @@ fi
BLOCK_BEGIN="# --- BEGIN ADDON ENV (generated) ---"
BLOCK_END="# --- END ADDON ENV (generated) ---"
EXPORT_BLOCK_FILE="$(mktemp)"
EXPORT_BLOCK_FILE="$(mktemp_safe)"
trap 'rm -f "$EXPORT_BLOCK_FILE"' EXIT
{
@@ -148,7 +158,7 @@ is_shell_run_script() {
inject_block_into_file() {
local file="$1"
local tmp
tmp="$(mktemp)"
tmp="$(mktemp_safe)"
awk -v bfile="${EXPORT_BLOCK_FILE}" -v begin="${BLOCK_BEGIN}" -v end="${BLOCK_END}" '
function print_block() {