From: juyin Date: Wed, 30 Mar 2022 11:21:32 +0000 (+0800) Subject: libmisc: add check fopen return value in read_random_bytes() X-Git-Tag: 4.12~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a43d0b95c44b2c36025452b772b9d4b251281e3e;p=thirdparty%2Fshadow.git 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 --- diff --git a/libmisc/salt.c b/libmisc/salt.c index f8ac56696..ebf162fc1 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);