]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
libmisc: add check fopen return value in read_random_bytes()
authorjuyin <zhuyan34@huawei.com>
Wed, 30 Mar 2022 11:21:32 +0000 (19:21 +0800)
committerSerge Hallyn <serge@hallyn.com>
Mon, 4 Apr 2022 02:07:09 +0000 (21:07 -0500)
Returns null when fopen fails. Then, using fread with a null pointer will cause a segfault.

Signed-off-by: Yan Zhu <zhuyan34@huawei.com>
libmisc/salt.c

index f8ac566968d4d45aa8dac841c43112014a025e53..ebf162fc177a69c014c0ad11206993028e135e4a 100644 (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);