Skip to content

Commit

Permalink
Fix GH-9339: OpenSSL oid_file path check warning contains uninitializ…
Browse files Browse the repository at this point in the history
…ed path
  • Loading branch information
bukka committed Aug 17, 2022
1 parent 7c6316a commit 84dcf57
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ PHP NEWS
. Fixed bug GH-9033 (Loading blacklist file can fail due to negative length).
(cmb)

- OpenSSL:
. Fixed bug GH-9339 (OpenSSL oid_file path check warning contains
uninitialized path). (Jakub Zelenka)

- PDO_SQLite:
. Fixed bug GH-9032 (SQLite3 authorizer crashes on NULL values). (cmb)

Expand Down
6 changes: 3 additions & 3 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ static bool php_openssl_check_path_ex(
error_msg = "must not contain any null bytes";
error_type = E_ERROR;
} else if (expand_filepath(fs_file_path, real_path) == NULL) {
error_msg = "The argument must be a valid file path";
error_msg = "must be a valid file path";
}

if (error_msg != NULL) {
if (arg_num == 0) {
const char *option_title = option_name ? option_name : "unknown";
const char *option_label = is_from_array ? "array item" : "option";
php_error_docref(NULL, E_WARNING, "Path '%s' for %s %s %s",
real_path, option_title, option_label, error_msg);
php_error_docref(NULL, E_WARNING, "Path for %s %s %s",
option_title, option_label, error_msg);
} else if (is_from_array && option_name != NULL) {
php_openssl_check_path_error(
arg_num, error_type, "option %s array item %s", option_name, error_msg);
Expand Down
25 changes: 25 additions & 0 deletions ext/openssl/tests/gh9339.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-9339: oid_file path check warning contains uninitialized path
--SKIPIF--
<?php
if (!extension_loaded("openssl")) die("skip openssl not loaded");
?>
--FILE--
<?php
$configCode = <<<CONFIG
oid_file = %s
[ req ]
default_bits = 1024
CONFIG;

$configFile = __DIR__ . '/gh9339.cnf';
file_put_contents($configFile, sprintf($configCode, __DIR__ . '/' . str_repeat('a', 9000)));
openssl_pkey_new([ 'config' => $configFile ]);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh9339.cnf');
?>
--EXPECTF--

Warning: openssl_pkey_new(): Path for oid_file option must be a valid file path in %s on line %d

0 comments on commit 84dcf57

Please sign in to comment.