37 lines
983 B
C
37 lines
983 B
C
#define _POSIX_C_SOURCE 200809L
|
|
#include <errno.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/resource.h>
|
|
#include <unistd.h>
|
|
|
|
/* Test-only deterministic launcher for allocation-failure observers. Keeping
|
|
* setrlimit in a repository-built helper avoids depending on util-linux paths
|
|
* or shell-specific ulimit syntax. */
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
if (argc < 3) {
|
|
fputs("usage: sep-limitexec bytes program [arg ...]\n", stderr);
|
|
return 2;
|
|
}
|
|
errno = 0;
|
|
char *end = NULL;
|
|
unsigned long long value = strtoull(argv[1], &end, 10);
|
|
if (errno != 0 || end == argv[1] || *end != '\0') {
|
|
fputs("sep-limitexec: invalid limit\n", stderr);
|
|
return 2;
|
|
}
|
|
struct rlimit limit;
|
|
limit.rlim_cur = (rlim_t)value;
|
|
limit.rlim_max = (rlim_t)value;
|
|
if (setrlimit(RLIMIT_AS, &limit) != 0) {
|
|
fputs("sep-limitexec: setrlimit failed\n", stderr);
|
|
return 2;
|
|
}
|
|
execv(argv[2], &argv[2]);
|
|
fputs("sep-limitexec: exec failed\n", stderr);
|
|
return 127;
|
|
}
|