DragonFlyBSD Kernel Audit
DF-0965 / build_fixed.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-0965 fix-validation: apply fix to harness's twofish_src.c, rebuild, run
set -e
cd "$(dirname "$0")"
cp /usr/src/sys/crypto/twofish/twofish.c ./twofish_src.c
# Apply the same fix as fix.diff using sed.
# Replace the single-line k_len assignment with the validated switch.
sed -i'' -e '/ctx->k_len = key_len_bits \/ 64;   \/\* 2, 3 or 4 \*\//c\
    switch (key_len_bits) {\
    case 128:\
    case 192:\
    case 256:\
        ctx->k_len = key_len_bits / 64;   /* 2, 3 or 4 */\
        break;\
    default:\
        ctx->k_len = 0;\
        return;\
    }' twofish_src.c
# sanity: confirm the patched line is present
grep -q 'ctx->k_len = 0;' twofish_src.c && echo "PATCH_OK" || { echo "PATCH_FAILED"; exit 2; }
rm -f trigger
cc -I. -I/usr/src/sys -Wall -O2 -o trigger trigger.c
./trigger