#!/usr/bin/env bash # CWE-407 scan — SpiderMonkey JS engine (IonMonkey compiler, CFG, SCC) set -euo pipefail echo "# scan=spidermonkey host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" # Sparse clone of gecko-dev — only js/src cd /tmp git clone --depth 1 --filter=blob:none --sparse \ https://github.com/mozilla/gecko-dev geckosrc 2>&1 | tail -1 cd geckosrc git sparse-checkout set js/src 2>&1 | tail -1 SMROOT=/tmp/geckosrc/js/src GRAPH_KW="topolog|scc\b|strongly.connected|cycle|dfs\b|postorder|dominator|liveness|reachab|tarjan|register.alloc|ion\b" C_MEM='std::find[(]|\.Contains[(]|IsInVector\b|vector.*find\b|linear_search|Vector.*Contains|NodeVector.*find' [ -d "$SMROOT" ] || { echo "# ERROR: SpiderMonkey source not found"; exit 0; } echo "# roots: $SMROOT" find "$SMROOT" -name "*.cpp" -o -name "*.h" 2>/dev/null | sort | while IFS= read -r f; do gl=$(grep -inE "$GRAPH_KW" "$f" 2>/dev/null | cut -d: -f1 | head -5 || true) [ -z "$gl" ] && continue while IFS= read -r ln; do s=$(( ln > 20 ? ln - 20 : 1 )); e=$(( ln + 20 )) hit=$(sed -n "${s},${e}p" "$f" 2>/dev/null | grep -iE "$C_MEM" | head -1 | sed 's/^\s*//' || true) [ -n "$hit" ] && echo "CANDIDATE ${f}:${ln} ${hit}" done <<< "$gl" done echo "# scan complete"