Skip to content

Commit c96be7b

Browse files
tstarlingnikic
authored andcommitted
Use ASCII lower case for misc case folding
Use ASCII case conversion instead of locale-dependent case conversion in the following places: * grapheme_stripos() and grapheme_strripos() in the "fast" path * ldap_get_entries() * oci_pconnect() for case folding of parameters when constructing a key into the connection or session pool * SoapClient: case folding of function names * get_meta_tags(): case conversion of property names * http stream wrapper: header names * phpinfo(): anchor names * php_verror(): docref URLs * rfc1867.c: Content-Type boundary parameter name * streams.c: stream protocol names Using locale-dependent case folding for these cases is either unnecessary or actively incorrect. These functions could have misbehaved when used with certain locales (e.g. Turkish). Closes GH-7511.
1 parent 92d0abd commit c96be7b

File tree

11 files changed

+20
-22
lines changed

11 files changed

+20
-22
lines changed

ext/intl/grapheme/grapheme_string.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <unicode/ustring.h>
2828
#include <unicode/ubrk.h>
2929

30-
#include "ext/standard/php_string.h"
31-
3230
/* }}} */
3331

3432
#define GRAPHEME_EXTRACT_TYPE_COUNT 0
@@ -179,9 +177,9 @@ PHP_FUNCTION(grapheme_stripos)
179177
char *haystack_dup, *needle_dup;
180178
int32_t noffset = offset >= 0 ? offset : (int32_t)haystack_len + offset;
181179
needle_dup = estrndup(needle, needle_len);
182-
php_strtolower(needle_dup, needle_len);
180+
zend_str_tolower(needle_dup, needle_len);
183181
haystack_dup = estrndup(haystack, haystack_len);
184-
php_strtolower(haystack_dup, haystack_len);
182+
zend_str_tolower(haystack_dup, haystack_len);
185183

186184
found = php_memnstr(haystack_dup + noffset, needle_dup, needle_len, haystack_dup + haystack_len);
187185

@@ -295,9 +293,9 @@ PHP_FUNCTION(grapheme_strripos)
295293
char *needle_dup, *haystack_dup;
296294

297295
needle_dup = estrndup(needle, needle_len);
298-
php_strtolower(needle_dup, needle_len);
296+
zend_str_tolower(needle_dup, needle_len);
299297
haystack_dup = estrndup(haystack, haystack_len);
300-
php_strtolower(haystack_dup, haystack_len);
298+
zend_str_tolower(haystack_dup, haystack_len);
301299

302300
ret_pos = grapheme_strrpos_ascii(haystack_dup, haystack_len, needle_dup, needle_len, offset);
303301

ext/ldap/ldap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#define __STDC__ 1
4646
#endif
4747

48-
#include "ext/standard/php_string.h"
4948
#include "ext/standard/info.h"
5049

5150
#ifdef HAVE_LDAP_SASL
@@ -2012,7 +2011,8 @@ PHP_FUNCTION(ldap_get_entries)
20122011
ldap_value_free_len(ldap_value);
20132012

20142013
attr_len = strlen(attribute);
2015-
zend_hash_str_update(Z_ARRVAL(tmp1), php_strtolower(attribute, attr_len), attr_len, &tmp2);
2014+
zend_str_tolower(attribute, attr_len);
2015+
zend_hash_str_update(Z_ARRVAL(tmp1), attribute, attr_len, &tmp2);
20162016
add_index_string(&tmp1, num_attrib, attribute);
20172017

20182018
num_attrib++;

ext/oci8/oci8.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
10451045
smart_str_0(&hashed_details);
10461046

10471047
/* make it lowercase */
1048-
php_strtolower(ZSTR_VAL(hashed_details.s), ZSTR_LEN(hashed_details.s));
1048+
zend_str_tolower(ZSTR_VAL(hashed_details.s), ZSTR_LEN(hashed_details.s));
10491049

10501050
if (!exclusive && !new_password) {
10511051
bool found = 0;
@@ -2163,7 +2163,7 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
21632163
/* Session Pool Hash Key : oci8spool***username**edition**hashedpassword**dbname**charset */
21642164

21652165
smart_str_0(&spool_hashed_details);
2166-
php_strtolower(ZSTR_VAL(spool_hashed_details.s), ZSTR_LEN(spool_hashed_details.s));
2166+
zend_str_tolower(ZSTR_VAL(spool_hashed_details.s), ZSTR_LEN(spool_hashed_details.s));
21672167
/* }}} */
21682168

21692169
spool_out_zv = zend_hash_find(&EG(persistent_list), spool_hashed_details.s);

ext/soap/php_sdl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri)
11281128
char *tmp = estrdup(function->functionName);
11291129
int len = strlen(tmp);
11301130

1131-
if (zend_hash_str_add_ptr(&ctx.sdl->functions, php_strtolower(tmp, len), len, function) == NULL) {
1131+
zend_str_tolower(tmp, len);
1132+
if (zend_hash_str_add_ptr(&ctx.sdl->functions, tmp, len, function) == NULL) {
11321133
zend_hash_next_index_insert_ptr(&ctx.sdl->functions, function);
11331134
}
11341135
efree(tmp);
@@ -1139,7 +1140,8 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri)
11391140
}
11401141
tmp = estrdup(function->requestName);
11411142
len = strlen(tmp);
1142-
zend_hash_str_add_ptr(ctx.sdl->requests, php_strtolower(tmp, len), len, function);
1143+
zend_str_tolower(tmp, len);
1144+
zend_hash_str_add_ptr(ctx.sdl->requests, tmp, len, function);
11431145
efree(tmp);
11441146
}
11451147
}

ext/soap/soap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4070,7 +4070,7 @@ static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name) /* {{{
40704070

40714071
int len = strlen(function_name);
40724072
char *str = estrndup(function_name,len);
4073-
php_strtolower(str,len);
4073+
zend_str_tolower(str,len);
40744074
if (sdl != NULL) {
40754075
if ((tmp = zend_hash_str_find_ptr(&sdl->functions, str, len)) != NULL) {
40764076
efree(str);

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ PHP_FUNCTION(get_meta_tags)
490490
} else if (tok == TOK_CLOSETAG) {
491491
if (have_name) {
492492
/* For BC */
493-
php_strtolower(name, strlen(name));
493+
zend_str_tolower(name, strlen(name));
494494
if (have_content) {
495495
add_assoc_string(return_value, name, value);
496496
} else {

ext/standard/http_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
455455
}
456456

457457
/* Make lowercase for easy comparison against 'standard' headers */
458-
php_strtolower(ZSTR_VAL(tmp), ZSTR_LEN(tmp));
458+
zend_str_tolower(ZSTR_VAL(tmp), ZSTR_LEN(tmp));
459459
t = ZSTR_VAL(tmp);
460460

461461
if (!header_init) {

ext/standard/info.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <sys/utsname.h>
3535
#endif
3636
#include "url.h"
37-
#include "php_string.h"
3837

3938
#ifdef PHP_WIN32
4039
# include "winver.h"
@@ -135,7 +134,7 @@ PHPAPI ZEND_COLD void php_info_print_module(zend_module_entry *zend_module) /* {
135134
if (!sapi_module.phpinfo_as_text) {
136135
zend_string *url_name = php_url_encode(zend_module->name, strlen(zend_module->name));
137136

138-
php_strtolower(ZSTR_VAL(url_name), ZSTR_LEN(url_name));
137+
zend_str_tolower(ZSTR_VAL(url_name), ZSTR_LEN(url_name));
139138
php_info_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", ZSTR_VAL(url_name), zend_module->name);
140139

141140
efree(url_name);

main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "php_syslog.h"
4949
#include "fopen_wrappers.h"
5050
#include "ext/standard/php_standard.h"
51-
#include "ext/standard/php_string.h"
5251
#include "ext/date/php_date.h"
5352
#include "php_variables.h"
5453
#include "ext/standard/credits.h"
@@ -1013,7 +1012,8 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
10131012
while((p = strchr(docref_buf, '_')) != NULL) {
10141013
*p = '-';
10151014
}
1016-
docref = php_strtolower(docref_buf, doclen);
1015+
zend_str_tolower(docref_buf, doclen);
1016+
docref = docref_buf;
10171017
}
10181018

10191019
/* we have a docref for a function AND

main/rfc1867.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "php_globals.h"
2929
#include "php_variables.h"
3030
#include "rfc1867.h"
31-
#include "ext/standard/php_string.h"
3231
#include "zend_smart_string.h"
3332

3433
#ifndef DEBUG_FILE_UPLOAD
@@ -714,7 +713,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
714713
int content_type_len = (int)strlen(content_type_dup);
715714
char *content_type_lcase = estrndup(content_type_dup, content_type_len);
716715

717-
php_strtolower(content_type_lcase, content_type_len);
716+
zend_str_tolower(content_type_lcase, content_type_len);
718717
boundary = strstr(content_type_lcase, "boundary");
719718
if (boundary) {
720719
boundary = content_type_dup + (boundary - content_type_lcase);

main/streams/streams.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
18251825
if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, protocol, n))) {
18261826
char *tmp = estrndup(protocol, n);
18271827

1828-
php_strtolower(tmp, n);
1828+
zend_str_tolower(tmp, n);
18291829
if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, tmp, n))) {
18301830
char wrapper_name[32];
18311831

0 commit comments

Comments
 (0)