#!/bin/sh
# DF-2571 run script
#
# REQUIRES: ng_device module built + loaded + an /dev/ngd0 node created.
# On the default DragonFly kernel, ng_device is NOT built or loaded (dead code).
# This script documents what WOULD trigger the bug if the module were present.
#
# To attempt reproduction (requires root, module must be built from orphaned src):
#   ./trigger /dev/ngd0 w 65536   # ngdwrite VLA: char buf[65536] on 16KB stack
#   ./trigger /dev/ngd0 r 65536   # ngdread  VLA: char buf[65537] on 16KB stack
#
# EXPECTED ON VULNERABLE MODULE LOADED: kernel panic (stack overflow / double fault)
# OBSERVED ON DEFAULT KERNEL: module not loadable (dead code, cannot compile)
#
cd "$(dirname "$0")"
echo "=== DF-2571: ng_device stack VLA overflow ==="
echo "Checking if /dev/ngd0 exists..."
if [ -e /dev/ngd0 ]; then
    echo "/dev/ngd0 exists. Running trigger (read, size=65536)..."
    ./trigger /dev/ngd0 r 65536
    echo "RUN_EXIT=$?"
else
    echo "/dev/ngd0 does NOT exist."
    echo "The ng_device module is not built into the default DragonFly kernel"
    echo "and the orphaned source (sys/netgraph/ng_device.c) cannot compile"
    echo "against modern kernel headers (removed cdevsw API)."
    echo "See VERDICT.md for the full reachability analysis."
    echo "RUN_EXIT=0 (nothing to trigger)"
fi
