/*
 * DF-1918 fix-validation harness — models the EXACT predicate added by
 * fix.diff (mrsas_ioctl.c:323-324) and shows it rejects every input
 * vector that the buggy path wrote OOB.
 *
 * Build:  cc -O2 -o fixcheck fixcheck.c
 * Run:    ./fixcheck
 */
#include <stdio.h>
#include <stdint.h>

#define MRSAS_MFI_FRAME_SIZE 1024

/* Verbatim predicate from fix.diff DF-1918 (mrsas_ioctl.c:323-324). */
static int fixed_reject(uint32_t sense_off)
{
    if (sense_off > MRSAS_MFI_FRAME_SIZE - sizeof(unsigned long))
        return 1;
    return 0;
}

int main(void)
{
    struct { const char *label; uint32_t sense_off; } v[] = {
        { "in-bounds",    128u },
        { "edge",         MRSAS_MFI_FRAME_SIZE - (unsigned)sizeof(unsigned long) },
        { "oob-7",        MRSAS_MFI_FRAME_SIZE - 7u },
        { "oob-full",     MRSAS_MFI_FRAME_SIZE },
        { "oob-deep",     MRSAS_MFI_FRAME_SIZE + 4096u },
        { "wrap",         0xFFFFFFF8u },
    };
    unsigned rejected = 0, total = sizeof(v)/sizeof(v[0]);
    printf("DF-1918 fix check (mrsas_ioctl.c:323-324 patched predicate):\n");
    for (unsigned i = 0; i < total; i++) {
        int r = fixed_reject(v[i].sense_off);
        printf("  sense_off=0x%08x -> %s\n", v[i].sense_off,
               r ? "REJECTED (EINVAL) -- would have OOB-written"
                 : "accepted (in-bounds)");
        if (r) rejected++;
    }
    printf("  %u/%u vectors rejected by the fix predicate.\n", rejected, total);
    return 0;
}
