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:
parent
e9bf727253
commit
a43d0b95c4
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user