summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/lib')
-rw-r--r--util/libreboot-utils/lib/rand.c42
-rw-r--r--util/libreboot-utils/lib/string.c35
2 files changed, 38 insertions, 39 deletions
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 3a0a94bf..3155eec3 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -72,37 +72,20 @@
* or your program dies.
*/
-int
-win_lottery(char **buf) /* are u lucky? */
+void *
+rmalloc(size_t *rval)
{
- size_t size = 0;
- int rval;
-
- char *s1 = rmalloc(&size);
- char *s2 = rmalloc(&size);
-
- if (scmp(s1, s2, BUFSIZ + 2, &rval) >= 0 &&
- rval == 0)
- rval = 1; /* winner! */
- else
- rval = 0;
-
- (void) scat(s1, s2, BUFSIZ << 1, buf);
-
- free_if_null(&s1);
- free_if_null(&s2);
-
- return rval;
+ return if_err(rval == NULL, EFAULT) ?
+ NULL : mkrstr(*rval = rsize(BUFSIZ));
}
-void *
-rmalloc(size_t *rval)
+size_t
+rsize(size_t n)
{
- if (if_err(rval == NULL, EFAULT))
- return NULL;
+ size_t rval = SIZE_MAX;
+ for (; rval >= SIZE_MAX - (SIZE_MAX % n); rset(&rval, sizeof(rval)));
- rset(rval, sizeof(*rval));
- return mkrstr(*rval %= BUFSIZ);
+ return rval % n;
}
char *
@@ -114,7 +97,7 @@ mkrstr(size_t n) /* emulates spkmodem-decode */
if (n == 0)
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
- if (n == SIZE_MAX)
+ if (n >= SIZE_MAX - 1)
err_no_cleanup(0, EOVERFLOW, "mkrbuf: overflow");
if (if_err((s = mkrbuf(n + 1)) == NULL, EFAULT))
@@ -132,11 +115,14 @@ mkrstr(size_t n) /* emulates spkmodem-decode */
void *
mkrbuf(size_t n)
{
- void *buf;
+ void *buf = "";
if (n == 0)
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
+ if (n >= SIZE_MAX - 1)
+ err_no_cleanup(0, EOVERFLOW, "integer overflow in mkrbuf");
+
if ((buf = malloc(n)) == NULL)
err_no_cleanup(0, ENOMEM, "mkrbuf: malloc");
diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c
index b639f0a4..c6e09752 100644
--- a/util/libreboot-utils/lib/string.c
+++ b/util/libreboot-utils/lib/string.c
@@ -321,15 +321,28 @@ lbgetprogname(char *argv0)
return progname;
}
+int
+xpledgex(const char *promises, const char *execpromises)
+{
+ int saved_errno = errno;
+ (void) promises, (void) execpromises, (void) saved_errno;
+#ifdef __OpenBSD__
+ if (pledge(promises, execpromises) == -1)
+ err_no_cleanup(0, errno, "pledge");
+#endif
+ errno = saved_errno;
+ return 0;
+}
-
-
-
-
-
-
-
-
-
-
-
+int
+xunveilx(const char *path, const char *permissions)
+{
+ int saved_errno = errno;
+ (void) path, (void) permissions, (void) saved_errno;
+#ifdef __OpenBSD__
+ if (pledge(promises, execpromises) == -1)
+ err_no_cleanup(0, errno, "pledge");
+#endif
+ errno = saved_errno;
+ return 0;
+}