mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-20 15:03:44 +02:00
rand.c: fix initialisation bug in mrkbuf
should be null on bad return Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -118,7 +118,7 @@ mkrstr(size_t n) /* emulates spkmodem-decode */
|
|||||||
void *
|
void *
|
||||||
mkrbuf(size_t n)
|
mkrbuf(size_t n)
|
||||||
{
|
{
|
||||||
void *buf = "";
|
void *buf = NULL;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
|
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
|
||||||
|
|||||||
@@ -2,20 +2,74 @@
|
|||||||
* Copyright (c) 2026 Leah Rowe <leah@libreboot.org> /| |\
|
* Copyright (c) 2026 Leah Rowe <leah@libreboot.org> /| |\
|
||||||
Something something non-determinism / \ */
|
Something something non-determinism / \ */
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "include/common.h"
|
#include "include/common.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
spew_buf(const void *data, size_t len);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int same = 0;
|
int same = 0;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
(void) argc, (void) argv;
|
(void) argc, (void) argv;
|
||||||
xpledgex("stdio", NULL);
|
xpledgex("stdio", NULL);
|
||||||
|
|
||||||
if (rsize(SIZE_MAX) == rsize(SIZE_MAX))
|
buf = mkrbuf(BUFSIZ + 1);
|
||||||
|
if (!memcmp(buf, buf + (BUFSIZ >> 1), BUFSIZ >> 1))
|
||||||
same = 1;
|
same = 1;
|
||||||
|
|
||||||
printf("%s\n", same ? "You win!" : "You lose!");
|
if (argc < 2) /* no spew */
|
||||||
|
spew_buf(buf, BUFSIZ);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
fprintf(stderr, "\n%s\n", same ? "You win!" : "You lose!");
|
||||||
return same ^ 1;
|
return same ^ 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spew_buf(const void *data, size_t len)
|
||||||
|
{
|
||||||
|
const unsigned char *buf = data;
|
||||||
|
unsigned char c;
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
if (buf == NULL ||
|
||||||
|
len == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 16) {
|
||||||
|
|
||||||
|
printf("%08zx ", i);
|
||||||
|
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
|
||||||
|
if (i + j < len)
|
||||||
|
printf("%02x ", buf[i + j]);
|
||||||
|
else
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
if (j == 7)
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" |");
|
||||||
|
|
||||||
|
for (j = 0; j < 16 && i + j < len; j++) {
|
||||||
|
|
||||||
|
c = buf[i + j];
|
||||||
|
printf("%c", isprint(c) ? c : '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("|\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%08zx\n", len);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user