Skip to content

Commit 338d795

Browse files
committed
Audit zend_ini_string usage
1 parent 8da598e commit 338d795

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

ext/openssl/openssl_backend_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ void php_openssl_set_cert_locations(zval *return_value)
504504
add_assoc_string(return_value, "default_cert_dir_env", (char *) X509_get_default_cert_dir_env());
505505
add_assoc_string(return_value, "default_private_dir", (char *) X509_get_default_private_dir());
506506
add_assoc_string(return_value, "default_default_cert_area", (char *) X509_get_default_cert_area());
507-
add_assoc_string(return_value, "ini_cafile",
508-
zend_ini_string("openssl.cafile", sizeof("openssl.cafile")-1, 0));
509-
add_assoc_string(return_value, "ini_capath",
510-
zend_ini_string("openssl.capath", sizeof("openssl.capath")-1, 0));
507+
add_assoc_str(return_value, "ini_cafile",
508+
zend_string_copy(zend_ini_str(ZEND_STRL("openssl.cafile"), false)));
509+
add_assoc_str(return_value, "ini_capath",
510+
zend_string_copy(zend_ini_str(ZEND_STRL("openssl.capath"), false)));
511511
}
512512

513513
X509 *php_openssl_x509_from_str(

ext/openssl/xp_ssl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,16 +880,16 @@ static long php_openssl_load_stream_cafile(X509_STORE *cert_store, const char *c
880880
static zend_result php_openssl_enable_peer_verification(SSL_CTX *ctx, php_stream *stream) /* {{{ */
881881
{
882882
zval *val = NULL;
883-
char *cafile = NULL;
884-
char *capath = NULL;
883+
const char *cafile = NULL;
884+
const char *capath = NULL;
885885
php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract;
886886

887887
GET_VER_OPT_STRING("cafile", cafile);
888888
GET_VER_OPT_STRING("capath", capath);
889889

890890
if (cafile == NULL) {
891-
cafile = zend_ini_string("openssl.cafile", sizeof("openssl.cafile")-1, 0);
892-
cafile = strlen(cafile) ? cafile : NULL;
891+
const zend_string *cafile_str = zend_ini_str(ZEND_STRL("openssl.cafile"), false);
892+
cafile = ZSTR_LEN(cafile_str) ? ZSTR_VAL(cafile_str) : NULL;
893893
} else if (!sslsock->is_client) {
894894
/* Servers need to load and assign CA names from the cafile */
895895
STACK_OF(X509_NAME) *cert_names = SSL_load_client_CA_file(cafile);
@@ -902,8 +902,8 @@ static zend_result php_openssl_enable_peer_verification(SSL_CTX *ctx, php_stream
902902
}
903903

904904
if (capath == NULL) {
905-
capath = zend_ini_string("openssl.capath", sizeof("openssl.capath")-1, 0);
906-
capath = strlen(capath) ? capath : NULL;
905+
const zend_string *capath_str = zend_ini_str(ZEND_STRL("openssl.capath"), false);
906+
capath = ZSTR_LEN(capath_str) ? ZSTR_VAL(capath_str) : NULL;
907907
}
908908

909909
if (cafile || capath) {

ext/standard/basic_functions.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,17 +2029,16 @@ PHP_FUNCTION(ini_restore)
20292029
PHP_FUNCTION(set_include_path)
20302030
{
20312031
zend_string *new_value;
2032-
char *old_value;
20332032
zend_string *key;
20342033

20352034
ZEND_PARSE_PARAMETERS_START(1, 1)
20362035
Z_PARAM_PATH_STR(new_value)
20372036
ZEND_PARSE_PARAMETERS_END();
20382037

2039-
old_value = zend_ini_string("include_path", sizeof("include_path") - 1, 0);
2038+
zend_string *old_value = zend_ini_str("include_path", sizeof("include_path") - 1, false);
20402039
/* copy to return here, because alter might free it! */
20412040
if (old_value) {
2042-
RETVAL_STRING(old_value);
2041+
RETVAL_STR_COPY(old_value);
20432042
} else {
20442043
RETVAL_FALSE;
20452044
}

ext/zlib/zlib.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,6 @@ ZEND_GET_MODULE(php_zlib)
12651265
static PHP_INI_MH(OnUpdate_zlib_output_compression)
12661266
{
12671267
int int_value;
1268-
char *ini_value;
12691268
if (new_value == NULL) {
12701269
return FAILURE;
12711270
}
@@ -1277,9 +1276,9 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
12771276
} else {
12781277
int_value = (int) zend_ini_parse_quantity_warn(new_value, entry->name);
12791278
}
1280-
ini_value = zend_ini_string("output_handler", sizeof("output_handler") - 1, 0);
1279+
const zend_string *ini_value = zend_ini_str(ZEND_STRL("output_handler"), false);
12811280

1282-
if (ini_value && *ini_value && int_value) {
1281+
if (ini_value && ZSTR_LEN(ini_value) && int_value) {
12831282
php_error_docref("ref.outcontrol", E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
12841283
return FAILURE;
12851284
}

0 commit comments

Comments
 (0)