summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lottery.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/lottery.c')
-rw-r--r--util/libreboot-utils/lottery.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c
index 9e396d1d..4b607117 100644
--- a/util/libreboot-utils/lottery.c
+++ b/util/libreboot-utils/lottery.c
@@ -1,20 +1,62 @@
-/* SPDX-License-Identifier: MIT ( >:3 )
- * 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> /* (^.>) - 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) };
- 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]);
- 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! */
-} /* /| |
- / \ */
+#include <stdint.h>
+#include <stdlib.h> /* (^.>) - are u lucky? */
+#include <string.h> /* \| /= */
+#include "include/common.h" /* l \ */
+
+#define len_hell(x, y) ((((x) - (y)) < BUFSIZ) ? ((x) - (y)) : BUFSIZ)
+
+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;
+}