#!/usr/bin/env bash # CWE-407 scan — Redis (cluster topology, module graph) set -euo pipefail echo "# scan=redis host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" cd /tmp && git clone --depth 1 https://github.com/redis/redis redis 2>&1 | tail -1 GRAPH_KW="topolog|reachab|cluster.*path|path.*cluster|cycle|dfs\b|scc\b|strongly.connected|dependency|failover|slot.*migrat" C_MEM='listSearchKey\|listNodeValue\|listIndex\|listRotate\|for.*next\b.*->next\b|linear.*search\|listTypeGet' echo "# roots: /tmp/redis/src" find /tmp/redis/src -name "*.c" -o -name "*.h" | 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"