summaryrefslogtreecommitdiff
path: root/util/libreboot-utils
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-25 22:20:19 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:42 +0000
commite0319f0116629f946fe286c5969f4a8a0dcfb7cb (patch)
tree014a30724621d09398424ee7cda4f13d875bc9bc /util/libreboot-utils
parentdc7a02da2dd65fd7d9d4785bda9bf5467fc660c0 (diff)
util/libreboot-utils: randomisation test
to test the effectiveness of the rand function Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils')
-rw-r--r--util/libreboot-utils/.gitignore1
-rw-r--r--util/libreboot-utils/Makefile26
-rw-r--r--util/libreboot-utils/include/common.h1
-rw-r--r--util/libreboot-utils/lib/rand.c10
-rw-r--r--util/libreboot-utils/lottery.c51
5 files changed, 79 insertions, 10 deletions
diff --git a/util/libreboot-utils/.gitignore b/util/libreboot-utils/.gitignore
index fbf110f9..fbfbd130 100644
--- a/util/libreboot-utils/.gitignore
+++ b/util/libreboot-utils/.gitignore
@@ -1,6 +1,7 @@
/nvm
/nvmutil
/mkhtemp
+/lottery
*.bin
*.o
*.d
diff --git a/util/libreboot-utils/Makefile b/util/libreboot-utils/Makefile
index 692ebf0f..a48b8ef9 100644
--- a/util/libreboot-utils/Makefile
+++ b/util/libreboot-utils/Makefile
@@ -25,6 +25,7 @@ HELLFLAGS = $(STRICT) -Weverything
PROG = nvmutil
PROGMKH = mkhtemp
+PROGLOT = lottery
OBJS_NVMUTIL = \
obj/nvmutil.o \
@@ -48,11 +49,19 @@ OBJS_MKHTEMP = \
obj/lib/mkhtemp.o \
obj/lib/rand.o
+OBJS_LOTTERY = \
+ obj/lottery.o \
+ obj/lib/file.o \
+ obj/lib/string.o \
+ obj/lib/num.o \
+ obj/lib/mkhtemp.o \
+ obj/lib/rand.o
+
# default mode
CFLAGS_MODE = $(PORTABLE)
CC_MODE = $(CC)
-all: $(PROG) $(PROGMKH)
+all: $(PROG) $(PROGMKH) $(PROGLOT)
$(PROG): $(OBJS_NVMUTIL)
$(CC_MODE) $(OBJS_NVMUTIL) -o $(PROG) $(LDFLAGS)
@@ -60,9 +69,13 @@ $(PROG): $(OBJS_NVMUTIL)
$(PROGMKH): $(OBJS_MKHTEMP)
$(CC_MODE) $(OBJS_MKHTEMP) -o $(PROGMKH) $(LDFLAGS)
+$(PROGLOT): $(OBJS_LOTTERY)
+ $(CC_MODE) $(OBJS_LOTTERY) -o $(PROGLOT) $(LDFLAGS)
+
# ensure obj directory exists
$(OBJS_NVMUTIL): obj
$(OBJS_MKHTEMP): obj
+$(OBJS_LOTTERY): obj
obj:
mkdir obj || true
@@ -76,6 +89,9 @@ obj/nvmutil.o: nvmutil.c
obj/mkhtemp.o: mkhtemp.c
$(CC_MODE) $(CFLAGS_MODE) -c mkhtemp.c -o obj/mkhtemp.o
+obj/lottery.o: lottery.c
+ $(CC_MODE) $(CFLAGS_MODE) -c lottery.c -o obj/lottery.o
+
# library/helper objects
obj/lib/state.o: lib/state.c
@@ -113,19 +129,23 @@ obj/lib/rand.o: lib/rand.c
# install
-install: $(PROG) $(PROGMKH)
+install: $(PROG) $(PROGMKH) $(PROGLOT)
$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
$(INSTALL) $(PROG) $(DESTDIR)$(PREFIX)/bin/$(PROG)
chmod 755 $(DESTDIR)$(PREFIX)/bin/$(PROG)
$(INSTALL) $(PROGMKH) $(DESTDIR)$(PREFIX)/bin/$(PROGMKH)
chmod 755 $(DESTDIR)$(PREFIX)/bin/$(PROGMKH)
+ $(INSTALL) $(PROGLOT) $(DESTDIR)$(PREFIX)/bin/$(PROGLOT)
+ chmod 755 $(DESTDIR)$(PREFIX)/bin/$(PROGLOT)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(PROG)
rm -f $(DESTDIR)$(PREFIX)/bin/$(PROGMKH)
+ rm -f $(DESTDIR)$(PREFIX)/bin/$(PROGLOT)
clean:
- rm -f $(PROG) $(PROGMKH) $(OBJS_NVMUTIL) $(OBJS_MKHTEMP)
+ rm -f $(PROG) $(PROGMKH) $(OBJS_NVMUTIL) $(OBJS_MKHTEMP) \
+ $(OBJS_LOTTERY)
distclean: clean
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index 6d6d8d09..4668cffa 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -388,6 +388,7 @@ void *mkrbuf(size_t n);
void rset(void *buf, size_t n);
void *mkrbuf(size_t n);
char *mkrstr(size_t n);
+int win_lottery(void);
/* Helper functions for command: dump
*/
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 392ec2ba..29a756ed 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -100,17 +100,13 @@ win_lottery(void)
win:
free_if_null(&s1), free_if_null(&s2);
- err_no_cleanup(0, ELOTTERY,
- "Congratulations! you won the errno lottery");
-
- exit(1);
- return -1;
+ printf("Congratulations! you won the errno lottery!\n");
+ return 1;
err:
/* the lottery won you */
free_if_null(&s1), free_if_null(&s2);
err_no_cleanup(0, EFAULT, "lottery won you");
- exit(1);
- return -1;
+ return 0;
}
char *
diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c
new file mode 100644
index 00000000..f673a109
--- /dev/null
+++ b/util/libreboot-utils/lottery.c
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: MIT
+ * Copyright (c) 2026 Leah Rowe <leah@libreboot.org>
+ */
+
+#ifdef __OpenBSD__
+#include <sys/param.h> /* pledge(2) */
+#endif
+
+#include <stdio.h>
+#include "include/common.h"
+
+int
+main(int argc, char *argv[])
+{
+#if defined(__OpenBSD__) && defined(OpenBSD)
+#if (OpenBSD) >= 509
+ if (pledge("stdio", NULL) == -1)
+ err_no_cleanup(0, errno, "openbsd won it");
+#endif
+#endif
+
+ if (win_lottery()) {
+ printf("You won!");
+ return 0;
+ }
+
+ return 1;
+}/*
+
+
+ ( >:3 )
+ /| |\
+ / \
+
+
+
+
+
+ */
+
+
+
+
+
+
+
+
+
+
+
+