fix(scripts): use mktemp for state.json writes, not a fixed /tmp path
All checks were successful
Check / eval-and-lint (push) Successful in 6m57s
All checks were successful
Check / eval-and-lint (push) Successful in 6m57s
Ten state-mutating sites across seven scripts wrote through a predictable, world-writable temp path (`/tmp/state.json`, `/tmp/system-state.json`) before the atomic `sudo mv`. Because the `>` redirect runs as the invoking user (sudo doesn't cover redirects), the shared fixed path is a symlink/ TOCTOU target and collides if two of these run concurrently. Switch each to a per-invocation `mktemp`; the atomic rename into place is unchanged. nomarchy-theme-set already used a temp var for its home-state write — this makes its system-state write consistent and cleans the temp up on failure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@ fi
|
||||
|
||||
case "$dns" in
|
||||
Cloudflare|Google|DHCP)
|
||||
sudo jq --arg dns "$dns" '.dns = $dns' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE"
|
||||
tmp=$(mktemp); sudo jq --arg dns "$dns" '.dns = $dns' "$STATE_FILE" > "$tmp" && sudo mv "$tmp" "$STATE_FILE"
|
||||
;;
|
||||
|
||||
Custom)
|
||||
@@ -28,7 +28,7 @@ Custom)
|
||||
|
||||
# Convert to JSON array safely
|
||||
dns_array=$(echo "$dns_servers" | jq -R 'split(" ")')
|
||||
sudo jq --arg dns "Custom" --argjson servers "$dns_array" '.dns = $dns | .customDns = $servers' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE"
|
||||
tmp=$(mktemp); sudo jq --arg dns "Custom" --argjson servers "$dns_array" '.dns = $dns | .customDns = $servers' "$STATE_FILE" > "$tmp" && sudo mv "$tmp" "$STATE_FILE"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user