Skip to content

Commit cc759ce

Browse files
SecAI-Hubclaude
andcommitted
Fix apply-profile.sh: remove dead locals, fix env var ordering, use safe heredocs
- Remove unused local variables (status, profile, previous, detail, tmpfile) that shellcheck flagged as SC2034 — the function reads from env vars - Fix _OVERRIDE_FILE set after the python3 command that reads it - Use single-quoted heredocs with env vars (not ${shell_var} interpolation) for both override and state file readers, consistent with C6 fix pattern Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 38213ea commit cc759ce

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

files/system/usr/libexec/secure-ai/apply-profile.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ VALID_PROFILES="offline_private research full_lab"
4040
log() { echo "[apply-profile] $(date -u +%Y-%m-%dT%H:%M:%SZ) $*"; }
4141

4242
write_result() {
43-
local status="$1" profile="$2" previous="$3" detail="${4:-}"
44-
local tmpfile="${RESULT_FILE}.tmp"
43+
# Reads from env vars: _RES_STATUS, _RES_PROFILE, _RES_PREVIOUS, _RES_DETAIL, _RES_TMPFILE, _RES_FILE
4544
python3 << 'PYEOF'
4645
import json, os, sys
4746
result = {
@@ -94,16 +93,15 @@ read_current_profile() {
9493
# Operator override takes precedence (hard lock)
9594
if [ -f "$OPERATOR_OVERRIDE" ]; then
9695
local override
97-
override=$(python3 -c "
98-
import yaml, os, sys
96+
override=$(_OVERRIDE_FILE="$OPERATOR_OVERRIDE" python3 -c '
97+
import yaml, os
9998
try:
100-
with open(os.environ['_OVERRIDE_FILE']) as f:
99+
with open(os.environ["_OVERRIDE_FILE"]) as f:
101100
data = yaml.safe_load(f)
102-
print(data.get('profile', ''))
101+
print(data.get("profile", ""))
103102
except Exception:
104-
print('')
105-
" 2>/dev/null) || true
106-
_OVERRIDE_FILE="$OPERATOR_OVERRIDE" || true
103+
print("")
104+
' 2>/dev/null) || true
107105
if [ -n "$override" ] && validate_profile "$override"; then
108106
echo "$override"
109107
return 0
@@ -113,15 +111,15 @@ except Exception:
113111
# Read from runtime state
114112
if [ -f "$PROFILE_STATE" ]; then
115113
local current
116-
current=$(python3 -c "
117-
import json, sys
114+
current=$(_PS_FILE="$PROFILE_STATE" python3 -c '
115+
import json, os
118116
try:
119-
with open('${PROFILE_STATE}') as f:
117+
with open(os.environ["_PS_FILE"]) as f:
120118
data = json.load(f)
121-
print(data.get('active', ''))
119+
print(data.get("active", ""))
122120
except Exception:
123-
print('')
124-
" 2>/dev/null) || true
121+
print("")
122+
' 2>/dev/null) || true
125123
if [ -n "$current" ] && validate_profile "$current"; then
126124
echo "$current"
127125
return 0

0 commit comments

Comments
 (0)