libmisc: add check fopen return value in read_random_bytes()

Returns null when fopen fails. Then, using fread with a null pointer will cause a segfault.

Signed-off-by: Yan Zhu <zhuyan34@huawei.com>
This commit is contained in:
juyin 2022-03-30 19:21:32 +08:00 committed by Serge Hallyn
parent e9bf727253
commit a43d0b95c4
1 changed files with 3 additions and 0 deletions

View File

@ -175,6 +175,9 @@ static long read_random_bytes (void)
#else
FILE *f = fopen ("/dev/urandom", "r");
if (NULL == f) {
goto fail;
}
if (fread (&randval, sizeof (randval), 1, f) != 1) {
fclose(f);