Skip to content

Commit a8086be

Browse files
committed
Fix GH-18986: OpenSSL backend: incorrect RAND_{load,write}_file() return value check
As noted by the LibreSSL maintainer, these functions return -1 on error. This is further confirmed by my static analyzer that inferred the same thing for OpenSSL. Closes GH-19013.
1 parent 6b2b60f commit a8086be

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ PHP NEWS
3737
- OpenSSL:
3838
. Fixed bug #80770 (It is not possible to get client peer certificate with
3939
stream_socket_server). (Jakub Zelenka)
40+
. Fixed bug GH-18986 (OpenSSL backend: incorrect RAND_{load,write}_file()
41+
return value check). (nielsdos, botovq)
4042

4143
- PCNTL:
4244
. Fixed bug GH-18958 (Fatal error during shutdown after pcntl_rfork() or

ext/openssl/openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static int php_openssl_load_rand_file(const char * file, int *egdsocket, int *se
10951095
return SUCCESS;
10961096
#endif
10971097
}
1098-
if (file == NULL || !RAND_load_file(file, -1)) {
1098+
if (file == NULL || RAND_load_file(file, -1) < 0) {
10991099
if (RAND_status() == 0) {
11001100
php_openssl_store_errors();
11011101
php_error_docref(NULL, E_WARNING, "Unable to load random state; not enough random data!");
@@ -1122,7 +1122,7 @@ static int php_openssl_write_rand_file(const char * file, int egdsocket, int see
11221122
file = RAND_file_name(buffer, sizeof(buffer));
11231123
}
11241124
PHP_OPENSSL_RAND_ADD_TIME();
1125-
if (file == NULL || !RAND_write_file(file)) {
1125+
if (file == NULL || RAND_write_file(file) < 0) {
11261126
php_openssl_store_errors();
11271127
php_error_docref(NULL, E_WARNING, "Unable to write random state");
11281128
return FAILURE;

0 commit comments

Comments
 (0)