Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-26 22:36:44 +00:00
parent 1a09efbbbe
commit a29a3ac6f6
3 changed files with 46 additions and 37 deletions
+6
View File
@@ -22,6 +22,10 @@
#include <sys/syscall.h>
#endif
#ifdef __OpenBSD__ /* for pledge */
#include <unistd.h>
#endif
#define items(x) (sizeof((x)) / sizeof((x)[0]))
/* system prototypes
@@ -369,6 +373,8 @@ void write_mac_part(size_t partnum);
/* string functions
*/
int xunveilx(const char *path, const char *permissions);
int xpledgex(const char *promises, const char *execpromises);
int slen(const char *scmp, size_t maxlen,
size_t *rval);
int scmp(const char *a, const char *b,
+24 -11
View File
@@ -321,15 +321,28 @@ lbgetprogname(char *argv0)
return progname;
}
int
xpledgex(const char *promises, const char *execpromises)
{
int saved_errno = errno;
(void) promises, (void) execpromises, (void) saved_errno;
#ifdef __OpenBSD__
if (pledge(promises, execpromises) == -1)
err_no_cleanup(0, errno, "pledge");
#endif
errno = saved_errno;
return 0;
}
int
xunveilx(const char *path, const char *permissions)
{
int saved_errno = errno;
(void) path, (void) permissions, (void) saved_errno;
#ifdef __OpenBSD__
if (pledge(promises, execpromises) == -1)
err_no_cleanup(0, errno, "pledge");
#endif
errno = saved_errno;
return 0;
}
+16 -26
View File
@@ -1,30 +1,20 @@
/* SPDX-License-Identifier: MIT
* Copyright (c) 2026 Leah Rowe <leah@libreboot.org>
*/
/* SPDX-License-Identifier: MIT ( >:3 )
* Copyright (c) 2026 Leah Rowe <leah@libreboot.org> /| |\
/ \*/
#include <stdio.h>
#include <string.h>
#include "include/common.h"
static int rigged(char **s);
int
main(int argc, char *argv[])
{
#ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1)
err_no_cleanup(0, errno, "openbsd wins");
#endif
printf("%s\n", (argc = rigged(argv)) ? "You lose!" : "You win!");
return argc;
}
static int
rigged(char **s) /* are u lucky? */
{
#include <string.h> /* (^.>) - are u lucky? */
#include "include/common.h" /* \| /= */
static int rigged(char **s, int spew) { /* l \ */
size_t size[2] = { rsize(1 << 17), rsize(1 << 17) };
return !(size[0] && size[0] == size[1] && size[0] <= 1 << 18 &&
spew &= size[1] = !(size[0] && size[0] == size[1] && size[0] <=1<<18 &&
s != NULL) || memcmp(*s = mkrbuf(size[0] << 1), *s + size[0],
size[0]);
}/* ( >:3 )
/| |\ it could be you!
/ \ */
if (spew && !size[1]) printf("%s\n\n", *s);
return size[1];
} /* (^:3) - it could be you! */
int main(int argc, char **argv) { /* /| |l */
xpledgex("stdio", NULL); /* / \ */
printf("%s\n", (argc = rigged(argv, argc > 1))?"You lose!":"You win!");
return argc; /* (^.^)/ - come again soon! */
} /* /| |
/ \ */