diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-26 22:36:44 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-26 22:48:03 +0000 |
| commit | a5d53ca39c4ebb47ee76e0e2e6f8a0533e6eeebb (patch) | |
| tree | 5fb1f1460e46cfaa6660c00eb2fa239930a3a66e /util/libreboot-utils | |
| parent | 1a09efbbbeda9caca912f4d07edc7b309c1dc6f4 (diff) | |
cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils')
| -rw-r--r-- | util/libreboot-utils/include/common.h | 6 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/string.c | 35 | ||||
| -rw-r--r-- | util/libreboot-utils/lottery.c | 36 |
3 files changed, 43 insertions, 34 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index 7f063a8c..1bef0d50 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -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, diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index b639f0a4..c6e09752 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -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; +} diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c index 9f84d043..f65b8d52 100644 --- a/util/libreboot-utils/lottery.c +++ b/util/libreboot-utils/lottery.c @@ -2,29 +2,19 @@ * 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! - / \ */
\ No newline at end of file + if (spew) 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! */ +} /* /| | + / \ */ |
