Skip to content

Commit e1ddca4

Browse files
committed
Use locale-independent alternatives to isalpha/isalnum/isctrl
- Avoid registering/detecting stream wrappers in locale-independent ways. - Avoid this in libmagic for detecting magic file headers. I don't believe these should be locale dependent. - Avoid locale dependence for http/ftp/network protocols. - Avoid locale dependence for Windows drive letter names in zend_virtual_cwd - Make parse_url stop depending on locale Related to https://bugs.php.net/bug.php?id=52923 iscntrl is locale-dependent which seems to corrupt certain bytes. Somewhat related to https://wiki.php.net/rfc/strtolower-ascii but I don't think most of these should have been locale-dependent in the first place - the code may not have considered locales E.g. on Linux, `setlocale(LC_ALL, 'de_DE');` (if the locale is installed and it succeeds) will have some values for alpha/cntrl in the range 128-256 where the C locale has no values. To avoid this locale-dependence in older php versions, applications can set `setlocale(LC_CTYPE, 'C')`.
1 parent 3c73225 commit e1ddca4

30 files changed

+113
-46
lines changed

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
18901890
/* Note that on Win32 CWD is per drive (heritage from CP/M).
18911891
* This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
18921892
*/
1893-
if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
1893+
if ((2 <= len) && zend_isalpha_ascii((int)((unsigned char *)path)[0]) && (':' == path[1])) {
18941894
/* Skip over the drive spec (if any) so as not to change */
18951895
path += 2;
18961896
len_adjust += 2;

Zend/zend_operators.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,70 @@ ZEND_API const unsigned char zend_toupper_map[256] = {
118118
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
119119
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
120120
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
121-
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
121+
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
122+
};
123+
124+
/* ctype's isalpha varies based on locale, which is not what we want for many use cases.
125+
* This is what it'd be in the "C" locale. */
126+
ZEND_API const bool zend_isalpha_map[256] = {
127+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
128+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
129+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
130+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
131+
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
132+
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
133+
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
134+
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
135+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
136+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
137+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
138+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
139+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
140+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
141+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
142+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
122143
};
123144

145+
/* ctype's isalnum is isalpha + isdigit(0-9) */
146+
ZEND_API const bool zend_isalnum_map[256] = {
147+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
148+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
149+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
150+
1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
151+
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
152+
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
153+
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
154+
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
155+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
156+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
157+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
158+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
159+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
160+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
161+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
162+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
163+
};
164+
165+
/* ctype's iscntrl varies based on locale, which is not what we want for many use cases.
166+
* This is what it'd be in the "C" locale. */
167+
ZEND_API const bool zend_iscntrl_map[256] = {
168+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
169+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
170+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
171+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
172+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
173+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
174+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
175+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
176+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
177+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
178+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
179+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
180+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
181+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
183+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
184+
};
124185

125186
/**
126187
* Functions using locale lowercase:

Zend/zend_operators.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,15 @@ ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2);
435435

436436
ZEND_API extern const unsigned char zend_tolower_map[256];
437437
ZEND_API extern const unsigned char zend_toupper_map[256];
438+
ZEND_API extern const bool zend_isalpha_map[256];
439+
ZEND_API extern const bool zend_isalnum_map[256];
440+
ZEND_API extern const bool zend_iscntrl_map[256];
438441

439442
#define zend_tolower_ascii(c) (zend_tolower_map[(unsigned char)(c)])
440443
#define zend_toupper_ascii(c) (zend_toupper_map[(unsigned char)(c)])
444+
#define zend_isalpha_ascii(c) (zend_isalpha_map[(unsigned char)(c)])
445+
#define zend_isalnum_ascii(c) (zend_isalnum_map[(unsigned char)(c)])
446+
#define zend_iscntrl_ascii(c) (zend_iscntrl_map[(unsigned char)(c)])
441447

442448
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t length);
443449
ZEND_API void ZEND_FASTCALL zend_str_toupper(char *str, size_t length);

Zend/zend_virtual_cwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef unsigned short mode_t;
8282
#define IS_UNC_PATH(path, len) \
8383
(len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1]))
8484
#define IS_ABSOLUTE_PATH(path, len) \
85-
(len >= 2 && (/* is local */isalpha(path[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
85+
(len >= 2 && (/* is local */zend_isalpha_ascii(path[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
8686

8787
#else
8888
#ifdef HAVE_DIRENT_H

ext/fileinfo/libmagic/apprentice.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ get_standard_integer_type(const char *l, const char **t)
299299
{
300300
int type;
301301

302-
if (isalpha(CAST(unsigned char, l[1]))) {
302+
if (zend_isalpha_ascii(CAST(unsigned char, l[1]))) {
303303
switch (l[1]) {
304304
case 'C':
305305
/* "dC" and "uC" */
@@ -1187,7 +1187,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
11871187
continue;
11881188
}
11891189
if ((*bang[i].fun)(ms, &me,
1190-
line + bang[i].len + 2,
1190+
line + bang[i].len + 2,
11911191
len - bang[i].len - 2) != 0) {
11921192
(*errs)++;
11931193
continue;
@@ -1419,7 +1419,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
14191419
/* coalesce per file arrays into a single one, if needed */
14201420
if (mset[j].count == 0)
14211421
continue;
1422-
1422+
14231423
if (coalesce_entries(ms, mset[j].me, mset[j].count,
14241424
&map->magic[j], &map->nmagic[j]) == -1) {
14251425
errs++;
@@ -2071,7 +2071,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
20712071
if (*l == 'd')
20722072
m->type = get_standard_integer_type(l, &l);
20732073
else if (*l == 's'
2074-
&& !isalpha(CAST(unsigned char, l[1]))) {
2074+
&& !zend_isalpha_ascii(CAST(unsigned char, l[1]))) {
20752075
m->type = FILE_STRING;
20762076
++l;
20772077
}
@@ -2287,7 +2287,7 @@ parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
22872287
private int
22882288
goodchar(unsigned char x, const char *extra)
22892289
{
2290-
return (isascii(x) && isalnum(x)) || strchr(extra, x);
2290+
return (zend_isalnum_ascii(x)) || strchr(extra, x);
22912291
}
22922292

22932293
private int

ext/fileinfo/libmagic/compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ format_decompression_error(struct magic_set *ms, size_t i, unsigned char *buf)
237237
return file_printf(ms, "ERROR:[%s: %s]", methodname(i), buf);
238238

239239
for (p = buf; *p; p++)
240-
if (!isalnum(*p))
240+
if (!zend_isalnum_ascii(*p))
241241
*p = '-';
242242

243243
return file_printf(ms, "application/x-decompression-error-%s-%s",

ext/fileinfo/libmagic/encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ looks_ucs32(const unsigned char *bf, size_t nbytes, file_unichar_t *ubf,
536536
| (CAST(file_unichar_t, bf[i]) << 24);
537537
else
538538
ubf[(*ulen)++] = CAST(file_unichar_t, bf[i + 0])
539-
| (CAST(file_unichar_t, bf[i + 1]) << 8)
539+
| (CAST(file_unichar_t, bf[i + 1]) << 8)
540540
| (CAST(file_unichar_t, bf[i + 2]) << 16)
541541
| (CAST(file_unichar_t, bf[i + 3]) << 24);
542542

ext/fileinfo/libmagic/funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ file_checkfmt(char *msg, size_t mlen, const char *fmt)
120120
return -1;
121121
}
122122

123-
if (!isalpha((unsigned char)*p)) {
123+
if (!zend_isalpha_ascii((unsigned char)*p)) {
124124
if (msg)
125125
snprintf(msg, mlen, "bad format char: %c", *p);
126126
return -1;

ext/filter/logical_filters.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,21 @@ static int _php_filter_validate_domain(char * domain, int len, zend_long flags)
528528
}
529529

530530
/* First char must be alphanumeric */
531-
if(*s == '.' || (hostname && !isalnum((int)*(unsigned char *)s))) {
531+
if(*s == '.' || (hostname && !zend_isalnum_ascii((int)*(unsigned char *)s))) {
532532
return 0;
533533
}
534534

535535
while (s < e) {
536536
if (*s == '.') {
537537
/* The first and the last character of a label must be alphanumeric */
538-
if (*(s + 1) == '.' || (hostname && (!isalnum((int)*(unsigned char *)(s - 1)) || !isalnum((int)*(unsigned char *)(s + 1))))) {
538+
if (*(s + 1) == '.' || (hostname && (!zend_isalnum_ascii((int)*(unsigned char *)(s - 1)) || !zend_isalnum_ascii((int)*(unsigned char *)(s + 1))))) {
539539
return 0;
540540
}
541541

542542
/* Reset label length counter */
543543
i = 1;
544544
} else {
545-
if (i > 63 || (hostname && *s != '-' && !isalnum((int)*(unsigned char *)s))) {
545+
if (i > 63 || (hostname && *s != '-' && !zend_isalnum_ascii((int)*(unsigned char *)s))) {
546546
return 0;
547547
}
548548

@@ -569,7 +569,7 @@ static int is_userinfo_valid(zend_string *str)
569569
const char *valid = "-._~!$&'()*+,;=:";
570570
const char *p = ZSTR_VAL(str);
571571
while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) {
572-
if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) {
572+
if (zend_isalnum_ascii(*p) || strchr(valid, *p)) {
573573
p++;
574574
} else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) {
575575
p += 3;

ext/gd/libgd/gd_xbm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
190190
name = estrdup("image");
191191
} else {
192192
for (i=0; i<l; i++) {
193-
/* only in C-locale isalnum() would work */
194-
if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
193+
/* Locale-independent check */
194+
if (!zend_isalnum_ascii(name[i])) {
195195
name[i] = '_';
196196
}
197197
}

ext/imap/php_imap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ PHP_FUNCTION(imap_utf8)
23062306
#define SPECIAL(c) ((c) <= 0x1f || (c) >= 0x7f)
23072307

23082308
/* validate a modified-base64 character */
2309-
#define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == ',')
2309+
#define B64CHAR(c) (zend_isalnum_ascii(c) || (c) == '+' || (c) == ',')
23102310

23112311
/* map the low 64 bits of `n' to the modified-base64 characters */
23122312
#define B64(n) ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" \

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3622,7 +3622,7 @@ PHP_FUNCTION(mb_send_mail)
36223622
to_r[to_len - 1] = '\0';
36233623
}
36243624
for (i = 0; to_r[i]; i++) {
3625-
if (iscntrl((unsigned char) to_r[i])) {
3625+
if (zend_iscntrl_ascii((unsigned char) to_r[i])) {
36263626
/* According to RFC 822, section 3.1.1 long headers may be separated into
36273627
* parts using CRLF followed at least one linear-white-space character ('\t' or ' ').
36283628
* To prevent these separators from being replaced with a space, we skip over them. */

ext/standard/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,10 +2405,10 @@ php_meta_tags_token php_next_meta_token(php_meta_tags_data *md)
24052405
break;
24062406

24072407
default:
2408-
if (isalnum(ch)) {
2408+
if (zend_isalnum_ascii(ch)) {
24092409
md->token_len = 0;
24102410
buff[(md->token_len)++] = ch;
2411-
while (!php_stream_eof(md->stream) && (ch = php_stream_getc(md->stream)) && (isalnum(ch) || strchr(PHP_META_HTML401_CHARS, ch))) {
2411+
while (!php_stream_eof(md->stream) && (ch = php_stream_getc(md->stream)) && (zend_isalnum_ascii(ch) || strchr(PHP_META_HTML401_CHARS, ch))) {
24122412
buff[(md->token_len)++] = ch;
24132413

24142414
if (md->token_len == META_DEF_BUFSIZE) {
@@ -2417,7 +2417,7 @@ php_meta_tags_token php_next_meta_token(php_meta_tags_data *md)
24172417
}
24182418

24192419
/* This is ugly, but we have to replace ungetc */
2420-
if (!isalpha(ch) && ch != '-') {
2420+
if (!zend_isalnum_ascii(ch) && ch != '-') {
24212421
md->ulc = 1;
24222422
md->lc = ch;
24232423
}

ext/standard/formatted_print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
466466

467467
PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n",
468468
*format, format - Z_STRVAL_P(z_format)));
469-
if (isalpha((int)*format)) {
469+
if (zend_isalpha_ascii((int)*format)) {
470470
width = precision = 0;
471471
argnum = ARG_NUM_NEXT;
472472
} else {

ext/standard/ftp_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
228228
#define PHP_FTP_CNTRL_CHK(val, val_len, err_msg) { \
229229
unsigned char *s = (unsigned char *) val, *e = (unsigned char *) s + val_len; \
230230
while (s < e) { \
231-
if (iscntrl(*s)) { \
231+
if (zend_iscntrl_ascii(*s)) { \
232232
php_stream_wrapper_log_error(wrapper, options, err_msg, val); \
233233
goto connect_errexit; \
234234
} \

ext/standard/http_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
895895
ZSTR_LEN(val) = php_url_decode(ZSTR_VAL(val), ZSTR_LEN(val)); \
896896
s = (unsigned char*)ZSTR_VAL(val); e = s + ZSTR_LEN(val); \
897897
while (s < e) { \
898-
if (iscntrl(*s)) { \
898+
if (zend_iscntrl_ascii(*s)) { \
899899
php_stream_wrapper_log_error(wrapper, options, "Invalid redirect URL! %s", new_path); \
900900
goto out; \
901901
} \

ext/standard/mail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ PHP_FUNCTION(mail)
242242
to_r[to_len - 1] = '\0';
243243
}
244244
for (i = 0; to_r[i]; i++) {
245-
if (iscntrl((unsigned char) to_r[i])) {
245+
if (zend_iscntrl_ascii((unsigned char) to_r[i])) {
246246
/* According to RFC 822, section 3.1.1 long headers may be separated into
247247
* parts using CRLF followed at least one linear-white-space character ('\t' or ' ').
248248
* To prevent these separators from being replaced with a space, we use the
@@ -264,7 +264,7 @@ PHP_FUNCTION(mail)
264264
subject_r[subject_len - 1] = '\0';
265265
}
266266
for (i = 0; subject_r[i]; i++) {
267-
if (iscntrl((unsigned char) subject_r[i])) {
267+
if (zend_iscntrl_ascii((unsigned char) subject_r[i])) {
268268
SKIP_LONG_HEADER_SEP(subject_r, i);
269269
subject_r[i] = ' ';
270270
}

ext/standard/metaphone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ static const char _codes[26] =
7777
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
7878
};
7979

80-
81-
#define ENCODE(c) (isalpha(c) ? _codes[((toupper(c)) - 'A')] : 0)
80+
/* Here, this avoids locale dependency to ensure the index is a valid index of _codes. */
81+
#define ENCODE(c) (zend_isalpha_ascii(c) ? _codes[((zend_toupper_ascii(c)) - 'A')] : 0)
8282

8383
#define isvowel(c) (ENCODE(c) & 1) /* AEIOU */
8484

ext/standard/quot_print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt
158158
length--;
159159
lp = 0;
160160
} else {
161-
if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) {
161+
if (zend_iscntrl_ascii(c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) {
162162
if ((((lp+= 3) > PHP_QPRINT_MAXL) && (c <= 0x7f))
163163
|| ((c > 0x7f) && (c <= 0xdf) && ((lp + 3) > PHP_QPRINT_MAXL))
164164
|| ((c > 0xdf) && (c <= 0xef) && ((lp + 6) > PHP_QPRINT_MAXL))

ext/standard/url.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PHPAPI char *php_replace_controlchars_ex(char *str, size_t len)
6161

6262
while (s < e) {
6363

64-
if (iscntrl(*s)) {
64+
if (zend_iscntrl_ascii(*s)) {
6565
*s='_';
6666
}
6767
s++;
@@ -117,7 +117,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
117117
p = s;
118118
while (p < e) {
119119
/* scheme = 1*[ lowalpha | digit | "+" | "-" | "." ] */
120-
if (!isalpha(*p) && !isdigit(*p) && *p != '+' && *p != '.' && *p != '-') {
120+
if (!zend_isalnum_ascii(*p) && *p != '+' && *p != '.' && *p != '-') {
121121
if (e + 1 < ue && e < binary_strcspn(s, ue, "?#")) {
122122
goto parse_port;
123123
} else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */

ext/standard/versioning.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ php_canonicalize_version(const char *version)
5959
*q++ = '.';
6060
}
6161
*q++ = *p;
62-
} else if (!isalnum(*p)) {
62+
} else if (!zend_isalnum_ascii(*p)) {
6363
if (lq != '.') {
6464
*q++ = '.';
6565
}

main/fopen_wrappers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
485485
}
486486

487487
/* Don't resolve paths which contain protocol (except of file://) */
488-
for (p = filename; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
488+
for (p = filename; zend_isalnum_ascii((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
489489
if ((*p == ':') && (p - filename > 1) && (p[1] == '/') && (p[2] == '/')) {
490490
wrapper = php_stream_locate_url_wrapper(filename, &actual_path, STREAM_OPEN_FOR_INCLUDE);
491491
if (wrapper == &php_plain_files_wrapper) {
@@ -517,7 +517,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
517517
/* Check for stream wrapper */
518518
int is_stream_wrapper = 0;
519519

520-
for (p = ptr; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
520+
for (p = ptr; zend_isalnum_ascii((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
521521
if ((*p == ':') && (p - ptr > 1) && (p[1] == '/') && (p[2] == '/')) {
522522
/* .:// or ..:// is not a stream wrapper */
523523
if (p[-1] != '.' || p[-2] != '.' || p - 2 != ptr) {
@@ -586,7 +586,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
586586
actual_path = trypath;
587587

588588
/* Check for stream wrapper */
589-
for (p = trypath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
589+
for (p = trypath; zend_isalnum_ascii((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++);
590590
if ((*p == ':') && (p - trypath > 1) && (p[1] == '/') && (p[2] == '/')) {
591591
wrapper = php_stream_locate_url_wrapper(trypath, &actual_path, STREAM_OPEN_FOR_INCLUDE);
592592
if (!wrapper) {

main/snprintf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ PHPAPI char * php_conv_fp(char format, double num,
288288
/*
289289
* Check for Infinity and NaN
290290
*/
291-
if (isalpha((int)*p)) {
291+
if (zend_isalpha_ascii((int)*p)) {
292292
*len = strlen(p);
293293
memcpy(buf, p, *len + 1);
294294
*is_negative = false;

0 commit comments

Comments
 (0)