#!/bin/sh
# DF-3643 source-trace reproduction: unchecked PHY-read returns -> uninit stack use
# Regenerates trace.log from the repo. Run from the repo root:
#   sh findings/poc/DF-3643/trace.sh > findings/poc/DF-3643/trace.log
F=sys/dev/netif/ig_hal/e1000_ich8lan.c

echo "== DF-3643 trace: unchecked PHY-read returns -> uninit stack use =="
echo "-- [site 1] e1000_set_eee_pchlan: declarations 909, unchecked read 959-961"
sed -n '905,910p' $F
sed -n '955,969p' $F
echo "-- [site 2] check_for_copper_link:1617-1626 RMW of uninit phy_reg (declared 1552)"
sed -n '1549,1553p' $F
sed -n '1616,1626p' $F
echo "-- [site 3] check_for_copper_link:1765-1772"
sed -n '1760,1773p' $F
echo "-- [site 4] lv_jumbo_workaround:2771-2773 unchecked read then OR/write-back"
sed -n '2770,2774p' $F
echo "-- [sites 5-8] lv_jumbo 2837-2859 further unchecked RMWs"
sed -n '2837,2859p' $F
echo
echo "-- upstream check: FreeBSD HEAD still identical --"
curl -s --max-time 30 \
  https://raw.githubusercontent.com/freebsd/freebsd-src/main/sys/dev/e1000/e1000_ich8lan.c \
  | grep -n "read_reg_locked(hw, PHY_LP_ABILITY, &data);" | head -2 \
  || echo "FETCH FAILED (check manually)"
