From d2c8dad96bd18423d94b30b1ddce5cce91459024 Mon Sep 17 00:00:00 2001 From: ndossche <7771979+ndossche@users.noreply.github.com> Date: Sun, 2 Aug 2026 14:17:57 +0200 Subject: [PATCH] rand: fix error check of RAND_load_file() This function returns -1 on error, or the number of bytes read on success. Preserve current behaviour and also error out on error. Discovered by an experimental static analyzer I work on. --- ext/openssl/ossl_rand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c index 753f8b25f..24e71e7f0 100644 --- a/ext/openssl/ossl_rand.c +++ b/ext/openssl/ossl_rand.c @@ -67,7 +67,7 @@ ossl_rand_add(VALUE self, VALUE str, VALUE entropy) static VALUE ossl_rand_load_file(VALUE self, VALUE filename) { - if(!RAND_load_file(StringValueCStr(filename), -1)) { + if (RAND_load_file(StringValueCStr(filename), -1) <= 0) { ossl_raise(eRandomError, NULL); } return Qtrue;