mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-19 08:01:17 +00:00
fix: use mktemp in _sprite_fix_config to prevent race conditions (#2359)
Replaces ${cfg}.fix$$ temp pattern with mktemp for guaranteed uniqueness.
Both temp file usages in the function are updated.
Fixes #2354
Agent: security-auditor
Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
62e1df9be5
commit
bd1399c861
1 changed files with 4 additions and 2 deletions
|
|
@ -31,14 +31,16 @@ _sprite_fix_config() {
|
|||
# The sprite CLI's concurrent writes append an extra } at the end.
|
||||
# Use grep on the whole file for any line that is just }}
|
||||
if grep -q '^}}$' "${cfg}" 2>/dev/null; then
|
||||
local tmp="${cfg}.fix$$"
|
||||
local tmp
|
||||
tmp=$(mktemp "${cfg}.XXXXXX") || return
|
||||
sed 's/^}}$/}/' "${cfg}" > "${tmp}" 2>/dev/null && mv "${tmp}" "${cfg}" 2>/dev/null || rm -f "${tmp}"
|
||||
fi
|
||||
# Also check if last non-empty line ends with }}
|
||||
local last_content
|
||||
last_content=$(tail -5 "${cfg}" | grep -v '^$' | tail -1)
|
||||
if printf '%s' "${last_content}" | grep -q '}}$'; then
|
||||
local tmp="${cfg}.fix$$"
|
||||
local tmp
|
||||
tmp=$(mktemp "${cfg}.XXXXXX") || return
|
||||
# Replace the LAST occurrence of }} with }
|
||||
sed '$ s/}}$/}/' "${cfg}" > "${tmp}" 2>/dev/null && mv "${tmp}" "${cfg}" 2>/dev/null || rm -f "${tmp}"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue