Skip to content

Commit 582514d

Browse files
committed
fix for bug#18556 - use simple tolower() function for internal things
1 parent d2beb0f commit 582514d

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

Zend/zend_operators.c

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,43 @@ static _locale_t current_locale = NULL;
4242

4343
#define TYPE_PAIR(t1,t2) (((t1) << 4) | (t2))
4444

45+
static unsigned char tolower_map[256] = {
46+
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
47+
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
48+
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
49+
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
50+
0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
51+
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
52+
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
53+
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
54+
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
55+
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
56+
0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
57+
0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
58+
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
59+
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
60+
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
61+
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
62+
};
63+
64+
#define zend_tolower_ascii(c) (tolower_map[(c)])
65+
66+
/**
67+
* Functions using locale lowercase:
68+
zend_binary_strncasecmp_l
69+
zend_binary_strcasecmp_l
70+
zend_binary_zval_strcasecmp
71+
zend_binary_zval_strncasecmp
72+
string_compare_function_ex
73+
string_case_compare_function
74+
* Functions using ascii lowercase:
75+
zend_str_tolower_copy
76+
zend_str_tolower_dup
77+
zend_str_tolower
78+
zend_binary_strcasecmp
79+
zend_binary_strncasecmp
80+
*/
81+
4582
ZEND_API int zend_atoi(const char *str, int str_len) /* {{{ */
4683
{
4784
int retval;
@@ -1908,7 +1945,7 @@ ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned in
19081945
register unsigned char *end = str + length;
19091946

19101947
while (str < end) {
1911-
*result++ = zend_tolower((int)*str++);
1948+
*result++ = zend_tolower_ascii((int)*str++);
19121949
}
19131950
*result = '\0';
19141951

@@ -1928,7 +1965,7 @@ ZEND_API void zend_str_tolower(char *str, unsigned int length) /* {{{ */
19281965
register unsigned char *end = p + length;
19291966

19301967
while (p < end) {
1931-
*p = zend_tolower((int)*p);
1968+
*p = zend_tolower_ascii((int)*p);
19321969
p++;
19331970
}
19341971
}
@@ -1975,6 +2012,49 @@ ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, u
19752012
return 0;
19762013
}
19772014

2015+
len = MIN(len1, len2);
2016+
while (len--) {
2017+
c1 = zend_tolower_ascii((int)*(unsigned char *)s1++);
2018+
c2 = zend_tolower_ascii((int)*(unsigned char *)s2++);
2019+
if (c1 != c2) {
2020+
return c1 - c2;
2021+
}
2022+
}
2023+
2024+
return len1 - len2;
2025+
}
2026+
/* }}} */
2027+
2028+
ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
2029+
{
2030+
int len;
2031+
int c1, c2;
2032+
2033+
if (s1 == s2) {
2034+
return 0;
2035+
}
2036+
len = MIN(length, MIN(len1, len2));
2037+
while (len--) {
2038+
c1 = zend_tolower_ascii((int)*(unsigned char *)s1++);
2039+
c2 = zend_tolower_ascii((int)*(unsigned char *)s2++);
2040+
if (c1 != c2) {
2041+
return c1 - c2;
2042+
}
2043+
}
2044+
2045+
return MIN(length, len1) - MIN(length, len2);
2046+
}
2047+
/* }}} */
2048+
2049+
ZEND_API int zend_binary_strcasecmp_l(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
2050+
{
2051+
int len;
2052+
int c1, c2;
2053+
2054+
if (s1 == s2) {
2055+
return 0;
2056+
}
2057+
19782058
len = MIN(len1, len2);
19792059
while (len--) {
19802060
c1 = zend_tolower((int)*(unsigned char *)s1++);
@@ -1988,7 +2068,7 @@ ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, u
19882068
}
19892069
/* }}} */
19902070

1991-
ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
2071+
ZEND_API int zend_binary_strncasecmp_l(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
19922072
{
19932073
int len;
19942074
int c1, c2;
@@ -2023,13 +2103,13 @@ ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3) /* {{{ */
20232103

20242104
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2) /* {{{ */
20252105
{
2026-
return zend_binary_strcasecmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
2106+
return zend_binary_strcasecmp_l(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
20272107
}
20282108
/* }}} */
20292109

20302110
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3) /* {{{ */
20312111
{
2032-
return zend_binary_strncasecmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2), Z_LVAL_P(s3));
2112+
return zend_binary_strncasecmp_l(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2), Z_LVAL_P(s3));
20332113
}
20342114
/* }}} */
20352115

@@ -2064,7 +2144,7 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
20642144
} else if (ret2!=IS_DOUBLE) {
20652145
if (oflow1) {
20662146
ZVAL_LONG(result, oflow1);
2067-
return;
2147+
return;
20682148
}
20692149
dval2 = (double) lval2;
20702150
} else if (dval1 == dval2 && !zend_finite(dval1)) {

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| [email protected] so we can mail you a copy immediately. |
1414
+----------------------------------------------------------------------+
1515
| Authors: Rasmus Lerdorf <[email protected]> |
16-
| Stig Sæther Bakken <[email protected]> |
16+
| Stig S�ther Bakken <[email protected]> |
1717
| Zeev Suraski <[email protected]> |
1818
+----------------------------------------------------------------------+
1919
*/
@@ -132,7 +132,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
132132
size_t i, j;
133133

134134
result = (unsigned char *) safe_emalloc(oldlen, 2 * sizeof(char), 1);
135-
135+
136136
for (i = j = 0; i < oldlen; i++) {
137137
result[j++] = hexconvtab[old[i] >> 4];
138138
result[j++] = hexconvtab[old[i] & 15];
@@ -5376,7 +5376,7 @@ PHP_FUNCTION(substr_compare)
53765376
if (!cs) {
53775377
RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
53785378
} else {
5379-
RETURN_LONG(zend_binary_strncasecmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
5379+
RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
53805380
}
53815381
}
53825382
/* }}} */

0 commit comments

Comments
 (0)