Skip to content

Commit 529b145

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
2 parents 63dcfb4 + b8dad93 commit 529b145

57 files changed

Lines changed: 175 additions & 175 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Zend/zend_compile.c

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

Zend/zend_ini.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static const char *zend_ini_consume_quantity_prefix(const char *const digits, co
584584
++digits_consumed;
585585
}
586586

587-
if (digits_consumed[0] == '0' && !isdigit(digits_consumed[1])) {
587+
if (digits_consumed[0] == '0' && !isdigit((unsigned char)digits_consumed[1])) {
588588
/* Value is just 0 */
589589
if ((digits_consumed+1) == str_end) {
590590
return digits_consumed;
@@ -642,7 +642,7 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
642642
}
643643

644644
/* if there is no digit after +/- */
645-
if (!isdigit(digits[0])) {
645+
if (!isdigit((unsigned char)digits[0])) {
646646
/* Escape the string to avoid null bytes and to make non-printable chars
647647
* visible */
648648
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
@@ -656,7 +656,7 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
656656
}
657657

658658
int base = 0;
659-
if (digits[0] == '0' && !isdigit(digits[1])) {
659+
if (digits[0] == '0' && !isdigit((unsigned char)digits[1])) {
660660
/* Value is just 0 */
661661
if ((digits+1) == str_end) {
662662
*errstr = NULL;

Zend/zend_operators.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,8 +3321,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1,
33213321

33223322
len = MIN(len1, len2);
33233323
while (len--) {
3324-
c1 = zend_tolower((int)*(unsigned char *)s1++);
3325-
c2 = zend_tolower((int)*(unsigned char *)s2++);
3324+
c1 = zend_tolower((unsigned char)*(s1++));
3325+
c2 = zend_tolower((unsigned char)*(s2++));
33263326
if (c1 != c2) {
33273327
return c1 - c2;
33283328
}
@@ -3342,8 +3342,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1
33423342
}
33433343
len = MIN(length, MIN(len1, len2));
33443344
while (len--) {
3345-
c1 = zend_tolower((int)*(unsigned char *)s1++);
3346-
c2 = zend_tolower((int)*(unsigned char *)s2++);
3345+
c1 = zend_tolower((unsigned char)*(s1++));
3346+
c2 = zend_tolower((unsigned char)*(s2++));
33473347
if (c1 != c2) {
33483348
return c1 - c2;
33493349
}

Zend/zend_virtual_cwd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void virtual_cwd_main_cwd_init(uint8_t reinit) /* {{{ */
193193
main_cwd_state.cwd_length = strlen(cwd);
194194
#ifdef ZEND_WIN32
195195
if (main_cwd_state.cwd_length >= 2 && cwd[1] == ':') {
196-
cwd[0] = toupper(cwd[0]);
196+
cwd[0] = toupper((unsigned char)cwd[0]);
197197
}
198198
#endif
199199
main_cwd_state.cwd = strdup(cwd);
@@ -269,7 +269,7 @@ CWD_API char *virtual_getcwd_ex(size_t *length) /* {{{ */
269269
*length = state->cwd_length+1;
270270
retval = (char *) emalloc(*length+1);
271271
memcpy(retval, state->cwd, *length);
272-
retval[0] = toupper(retval[0]);
272+
retval[0] = toupper((unsigned char)retval[0]);
273273
retval[*length-1] = DEFAULT_SLASH;
274274
retval[*length] = '\0';
275275
return retval;
@@ -1112,21 +1112,21 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
11121112
if (resolved_path[start] == 0) {
11131113
goto verify;
11141114
}
1115-
resolved_path[start] = toupper(resolved_path[start]);
1115+
resolved_path[start] = toupper((unsigned char)resolved_path[start]);
11161116
start++;
11171117
}
11181118
resolved_path[start++] = DEFAULT_SLASH;
11191119
while (!IS_SLASH(resolved_path[start])) {
11201120
if (resolved_path[start] == 0) {
11211121
goto verify;
11221122
}
1123-
resolved_path[start] = toupper(resolved_path[start]);
1123+
resolved_path[start] = toupper((unsigned char)resolved_path[start]);
11241124
start++;
11251125
}
11261126
resolved_path[start++] = DEFAULT_SLASH;
11271127
} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
11281128
/* skip DRIVE name */
1129-
resolved_path[0] = toupper(resolved_path[0]);
1129+
resolved_path[0] = toupper((unsigned char)resolved_path[0]);
11301130
resolved_path[2] = DEFAULT_SLASH;
11311131
if (path_length == 2) {
11321132
resolved_path[3] = '\0';

Zend/zend_virtual_cwd.h

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

9090
#else
9191
#ifdef HAVE_DIRENT_H

ext/com_dotnet/com_extension.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ static PHP_INI_MH(OnTypeLibFileUpdate)
116116
}
117117

118118
/* Remove leading/training white spaces on search_string */
119-
while (isspace(*typelib_name)) {/* Ends on '\0' in worst case */
119+
while (isspace((unsigned char)*typelib_name)) {/* Ends on '\0' in worst case */
120120
typelib_name ++;
121121
}
122122
ptr = typelib_name + strlen(typelib_name) - 1;
123-
while ((ptr != typelib_name) && isspace(*ptr)) {
123+
while ((ptr != typelib_name) && isspace((unsigned char)*ptr)) {
124124
*ptr = '\0';
125125
ptr--;
126126
}

ext/date/lib/parse_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)
518518

519519
static void timelib_skip_day_suffix(const char **ptr)
520520
{
521-
if (isspace(**ptr)) {
521+
if (isspace((unsigned char)**ptr)) {
522522
return;
523523
}
524524
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
@@ -859,7 +859,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)
859859

860860
*tz_not_found = 1;
861861

862-
while (isdigit(**ptr) || **ptr == ':') {
862+
while (isdigit((unsigned char)**ptr) || **ptr == ':') {
863863
++*ptr;
864864
}
865865
end = *ptr;
@@ -924,7 +924,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
924924
}
925925

926926
++*ptr;
927-
while (isdigit(**ptr)) {
927+
while (isdigit((unsigned char)**ptr)) {
928928
++*ptr;
929929
}
930930

ext/date/lib/parse_date.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)
516516

517517
static void timelib_skip_day_suffix(const char **ptr)
518518
{
519-
if (isspace(**ptr)) {
519+
if (isspace((unsigned char)**ptr)) {
520520
return;
521521
}
522522
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
@@ -857,7 +857,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)
857857

858858
*tz_not_found = 1;
859859

860-
while (isdigit(**ptr) || **ptr == ':') {
860+
while (isdigit((unsigned char)**ptr) || **ptr == ':') {
861861
++*ptr;
862862
}
863863
end = *ptr;
@@ -922,7 +922,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
922922
}
923923

924924
++*ptr;
925-
while (isdigit(**ptr)) {
925+
while (isdigit((unsigned char)**ptr)) {
926926
++*ptr;
927927
}
928928

ext/date/lib/parse_iso_intervals.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ void timelib_strtointerval(const char *s, size_t len,
985985
in.errors->error_messages = NULL;
986986

987987
if (len > 0) {
988-
while (isspace(*s) && s < e) {
988+
while (isspace((unsigned char)*s) && s < e) {
989989
s++;
990990
}
991-
while (isspace(*e) && e > s) {
991+
while (isspace((unsigned char)*e) && e > s) {
992992
e--;
993993
}
994994
}

ext/date/lib/parse_iso_intervals.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ void timelib_strtointerval(const char *s, size_t len,
343343
in.errors->error_messages = NULL;
344344

345345
if (len > 0) {
346-
while (isspace(*s) && s < e) {
346+
while (isspace((unsigned char)*s) && s < e) {
347347
s++;
348348
}
349-
while (isspace(*e) && e > s) {
349+
while (isspace((unsigned char)*e) && e > s) {
350350
e--;
351351
}
352352
}

0 commit comments

Comments
 (0)