From 4599df64cab89b72cf679d07d936151d61fb37a8 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 27 Mar 2026 03:09:41 +0000 Subject: util/libreboot-utils: finish implementing hell Signed-off-by: Leah Rowe --- util/libreboot-utils/lottery.c | 74 ++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'util/libreboot-utils/lottery.c') diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c index 76548191..4b607117 100644 --- a/util/libreboot-utils/lottery.c +++ b/util/libreboot-utils/lottery.c @@ -1,28 +1,62 @@ /* SPDX-License-Identifier: MIT ( >:3 ) - * Copyright (c) 2026 Leah Rowe /| |\*/ -#include /* / \ */ + * Copyright (c) 2026 Leah Rowe /| |\ + / \ */ +#include #include #include /* (^.>) - are u lucky? */ #include /* \| /= */ #include "include/common.h" /* l \ */ + #define len_hell(x, y) ((((x) - (y)) < BUFSIZ) ? ((x) - (y)) : BUFSIZ) -static int rigged(char **s) { - size_t size[3] = { rsize(SIZE_MAX), rsize(SIZE_MAX), 0 }; - if (!(size[0] && size[0]==size[1] && size[0]<=SIZE_MAX && s != NULL) || - ((size[0] & 1) && (*mkrstr(1) != *mkrstr(1)))) - return 1; - if (!(size[0] &= ~(size_t)1)) /* (^:3) - it could be you! */ - return 0; /* /| |l */ - if ((*s = malloc(BUFSIZ)) == NULL) /* / \ */ - 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)) - return 1; - } else return 1; - return 0; /* <---- winner! */ -} /* (^.^) - come again soon! */ -int main(int argc, char **argv) { /* /| |l */ - xpledgex("stdio", NULL); /* / \ */ - printf("%s", (argc = rigged(argv))? "You lose!\n" : ""); + +static int rigged(void) +{ + 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; + } + + 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; } -- cgit v1.2.1