You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/08/18 10:02:06 UTC
[incubator-nuttx-apps] branch master updated: apps: Fix bug by calling getrandom
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new c4972d472 apps: Fix bug by calling getrandom
c4972d472 is described below
commit c4972d4721b7c8c3e796ad8e8b3c5bfe3ceff5ae
Author: weizihan <we...@xiaomi.com>
AuthorDate: Tue Apr 19 20:22:59 2022 +0800
apps: Fix bug by calling getrandom
Signed-off-by: weizihan <we...@xiaomi.com>
---
fsutils/mkgpt/mkgpt.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fsutils/mkgpt/mkgpt.c b/fsutils/mkgpt/mkgpt.c
index 5b2c3d3f5..953b7fdd8 100644
--- a/fsutils/mkgpt/mkgpt.c
+++ b/fsutils/mkgpt/mkgpt.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <string.h>
+#include <sys/random.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -128,12 +129,12 @@ static const uint8_t g_partition_type_swap[16] =
static void get_uuid(FAR uint8_t *uuid)
{
- int fd;
- fd = open("/dev/urandom", O_RDONLY);
- if (fd > 0)
+ /* call getrandom to read /dev/urandom */
+
+ if (getrandom(uuid, 16, 0) < 0)
{
- read(fd, uuid, 16);
- close(fd);
+ fprintf(stderr, "error read primary partition table\n");
+ return;
}
}