java-topology/tools/scans/memcached.sh
russell@unturf.com db29a08762 undefect. CWE-407 — 92 sites, 42 ecosystems
B&W print-friendly diagrams + tinkerpop-0001 + wave-3 proof sections.
Squash of 94 local commits onto remote master.
2026-03-26 19:48:18 -04:00

20 lines
1,020 B
Bash
Executable file

#!/usr/bin/env bash
# CWE-407 scan — Memcached (connection/item graph, consistent hash ring)
set -euo pipefail
echo "# scan=memcached host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
cd /tmp && git clone --depth 1 https://github.com/memcached/memcached memcached 2>&1 | tail -1
GRAPH_KW="topolog|cycle|graph|reachab|consistent.hash|ring|node.*next|chain|slab.*chain"
C_MEM='linear_search|find_item_locked|item_get_locked|STAILQ_FOREACH.*==|TAILQ_FOREACH.*==|for.*->next.*==.*->next'
echo "# roots: /tmp/memcached"
find /tmp/memcached -name "*.c" -o -name "*.h" 2>/dev/null | grep -v t/ | 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"