#!/usr/bin/env bash # CWE-407 scan — MySQL Server (optimizer, graph, dependency resolution) set -euo pipefail echo "# scan=mysql host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" cd /tmp && git clone --depth 1 https://github.com/mysql/mysql-server mysql 2>&1 | tail -1 GRAPH_KW="topolog|cycle|dfs\b|scc\b|strongly.connected|reachab|dependency|graph|tarjan|postorder" C_MEM='std::find[(]|\.count[(]|list_search|find.*begin.*end|linear_search|List_iterator.*find|std::list.*find' for dir in sql storage/innobase; do [ -d /tmp/mysql/$dir ] || continue echo "# roots: /tmp/mysql/$dir" find /tmp/mysql/$dir -name "*.cc" -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 done echo "# scan complete"