diff options
Diffstat (limited to 'util/libreboot-utils/lottery.c')
| -rw-r--r-- | util/libreboot-utils/lottery.c | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c index 8157d7a9..4b607117 100644 --- a/util/libreboot-utils/lottery.c +++ b/util/libreboot-utils/lottery.c @@ -1,41 +1,62 @@ -/* SPDX-License-Identifier: MIT - * Copyright (c) 2026 Leah Rowe <leah@libreboot.org> - */ - -#ifdef __OpenBSD__ -#include <sys/param.h> /* pledge(2) */ -#endif - +/* SPDX-License-Identifier: MIT ( >:3 ) + * Copyright (c) 2026 Leah Rowe <leah@libreboot.org> /| |\ + / \ */ #include <stdio.h> -#include <stdlib.h> -#include "include/common.h" +#include <stdint.h> +#include <stdlib.h> /* (^.>) - are u lucky? */ +#include <string.h> /* \| /= */ +#include "include/common.h" /* l \ */ -int -main(int argc, char *argv[]) +#define len_hell(x, y) ((((x) - (y)) < BUFSIZ) ? ((x) - (y)) : BUFSIZ) + +static int rigged(void) { - char *s1 = NULL; - int rval = 0; - -#if defined(__OpenBSD__) && defined(OpenBSD) -#if (OpenBSD) >= 509 - if (pledge("stdio", NULL) == -1) - err_no_cleanup(0, errno, "openbsd won it"); -#endif -#endif - setvbuf(stdout, NULL, _IONBF, 0); - - if (win_lottery(&s1)) - rval = 1; - - if (s1 != NULL) { - printf("%s\n\n", s1); - free(s1); + size_t size[5] = { 0, 0, 0, SIZE_MAX, SIZE_MAX}; + char *b1 = NULL, *b2 = NULL; + char *s = NULL; +again: + if (!size[3]) { + if (!size[4]) + return 0; /* <--- WINNER!!! */ + else --size[4]; + } else --size[3]; + + free_and_set_null(&b1); + free_and_set_null(&b2); + + size[0] = rsize(SIZE_MAX); /* \( ^o^)/ - then come play! */ + size[1] = rsize(SIZE_MAX); /* | | */ +/* / \ */ + if (!(size[0] && (size[0] == size[1]) && (size[0] <= SIZE_MAX)) || + ((size[0] & 1) && (*(b1 = mkrstr(1)) != *(b2 = mkrstr(1))))) + goto out; /* \(^-^)/ - it could be you! */ + if (!(size[0] &= ~(size_t)1)) /* \ / */ + goto again; /* / \ */ + + if (s == NULL) { + if ((s = malloc(BUFSIZ)) == NULL) + goto out; } - printf("%s\n", rval ? "You won!" : "You lose! Sorry!"); - return rval? EXIT_SUCCESS : EXIT_FAILURE; -}/* - - ( >:3 ) - /| |\ - / \ */ + for (size[1] = 0; size[1] < size[0]; size[1] += BUFSIZ) { + rset(s, size[2] = len_hell(size[0], size[1])); + if (!memcmp(s, s + (size[2] >> 1), size[2] >> 1)) + goto out; + } + + goto again; +out: + free_and_set_null(&b1); + free_and_set_null(&b2); + free_and_set_null(&s); + + return 1; +} +/* \(^o^)/ - come again soon! */ +int main(int argc, char **argv) /* \ / */ +{ /* / \ */ + xpledgex("stdio", NULL); /* */ + printf("%s", (argc = rigged()) ? "You lose!\n" : ""); + + return argc; +} |
