summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-25 21:07:56 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-25 21:08:40 +0000
commit6adcb9fa3a053e53e8144610d95e6eca5749ecb5 (patch)
tree2ce5821d3e54f179b0f74613872fedb611867c4d /util
parent8d8d8871ce30be7585477ab2cb4f12d2a401009e (diff)
lbutils: new function, mkrbuf (random malloc)
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/libreboot-utils/include/common.h1
-rw-r--r--util/libreboot-utils/lib/rand.c18
2 files changed, 17 insertions, 2 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index 98fcfc27..c4ee75e0 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -384,6 +384,7 @@ int dcat(const char *s, size_t n,
*/
unsigned short hextonum(char ch_s);
+void *mkrbuf(size_t n);
void rset(void *buf, size_t n);
/* Helper functions for command: dump
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 31221d61..e67b7058 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -67,6 +67,21 @@
* or your program dies.
*/
+void *
+mkrbuf(size_t n)
+{
+ void *buf;
+
+ if (n == 0)
+ err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
+
+ if ((buf = malloc(n)) == NULL)
+ err_no_cleanup(0, ENOMEM, "mkrbuf: malloc");
+
+ rset(buf, n);
+ return buf; /* basically malloc() but with rand */
+}
+
void
rset(void *buf, size_t n)
{
@@ -76,8 +91,7 @@ rset(void *buf, size_t n)
goto err;
if (n == 0)
- err_no_cleanup(0, EPERM,
- "rset: zero-byte length request");
+ err_no_cleanup(0, EPERM, "rset: zero-byte request");
#if (defined(__OpenBSD__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__APPLE__) || \