34 lines
887 B
Diff
34 lines
887 B
Diff
From a43d0b95c44b2c36025452b772b9d4b251281e3e Mon Sep 17 00:00:00 2001
|
|
From: juyin <zhuyan34@huawei.com>
|
|
Date: Wed, 30 Mar 2022 19:21:32 +0800
|
|
Subject: [PATCH] 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>
|
|
|
|
Reference: https://github.com/shadow-maint/shadow/commit/a43d0b95c44b2c36025452b772b9d4b251281e3e
|
|
Conflict: NA
|
|
|
|
---
|
|
libmisc/salt.c | 3 +++
|
|
1 file changed, 3 insertions(+)
|
|
|
|
diff --git a/libmisc/salt.c b/libmisc/salt.c
|
|
index f8ac5669..ebf162fc 100644
|
|
--- a/libmisc/salt.c
|
|
+++ b/libmisc/salt.c
|
|
@@ -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);
|
|
--
|
|
2.27.0
|
|
|