php-src
php-src copied to clipboard
possible use of uninitialized value
Description
during review of some application code I came across implementation of allow_self_signed option of ssl_context and it seem to me that there's an uninitialized value used in condition expression
https://github.com/php/php-src/blob/master/ext/openssl/xp_ssl.c#L306
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) /* {{{ */
{
php_stream *stream;
SSL *ssl;
int err, depth, ret;
zval *val;
zend_ulong allowed_depth = OPENSSL_DEFAULT_STREAM_VERIFY_DEPTH;
ret = preverify_ok;
/* determine the status for the current cert */
err = X509_STORE_CTX_get_error(ctx);
depth = X509_STORE_CTX_get_error_depth(ctx);
/* conjure the stream & context to use */
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
stream = (php_stream*)SSL_get_ex_data(ssl, php_openssl_get_ssl_stream_data_index());
/* if allow_self_signed is set, make sure that verification succeeds */
if (err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT &&
GET_VER_OPT("allow_self_signed") &&
zend_is_true(val) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ??
) {
ret = 1;
}
/* check the depth */
GET_VER_OPT_LONG("verify_depth", allowed_depth);
if ((zend_ulong)depth > allowed_depth) {
ret = 0;
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_CHAIN_TOO_LONG);
}
return ret;
}
/* }}} */
PHP Version
php 8.0.18
Operating System
No response
Looks like it, but it's actually assigned by the GET_VER_OPT/GET_VER_OPT_LONG macro.
https://github.com/php/php-src/blob/8649cb8a9657f37ee4ea59b0b4c45dc120728333/ext/openssl/xp_ssl.c#L100-L101
Not the clearest code, but correct. Thanks for the report though!