/*
 * maxinflate.c — DF-0935 disproof harness. Maximally inflate all 12 rlimits
 * as an unprivileged user (setrlimit clamps silently for capped resources),
 * then read /proc/self/rlimit. Confirms the realistic ceiling on default
 * config: 431 bytes — well under psbuf[512].
 *
 * Build: cc -o maxinflate maxinflate.c
 * Run:   ./maxinflate
 */
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int main(void) {
    struct rlimit r = { RLIM_INFINITY - 1, RLIM_INFINITY - 1 };
    char path[64], buf[8192];
    int fd, i;
    int all[] = {
        RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA, RLIMIT_STACK,
        RLIMIT_CORE, RLIMIT_RSS, RLIMIT_MEMLOCK, RLIMIT_NPROC,
        RLIMIT_NOFILE, RLIMIT_SBSIZE, RLIMIT_VMEM, RLIMIT_POSIXLOCKS
    };

    for (i = 0; i < 12; i++) {
        if (setrlimit(all[i], &r) < 0) {
            /* EPERM means rlim_max bump attempted — falls back gracefully */
            perror("setrlimit");
        }
    }

    snprintf(path, sizeof(path), "/proc/%d/rlimit", (int)getpid());
    fd = open(path, O_RDONLY);
    if (fd < 0) { perror("open"); return 1; }
    ssize_t n = read(fd, buf, sizeof(buf));
    close(fd);

    printf("read %zd bytes from %s\n", n, path);
    if (n > 0) {
        if (write(1, buf, (size_t)n) < 0) perror("write");
    }
    printf("\n");
    printf("OVERFLOW? %s (psbuf holds 512 bytes)\n",
           n > 512 ? "YES" : "no (well under 512)");
    return 0;
}
