Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Zend/tests/GHSA-wm6j-2649-pv75.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GHSA-wm6j-2649-pv75: Null pointer dereference in php_mb_check_encoding() via mb_ereg_search_init()
--CREDITS--
vi3tL0u1s
--EXTENSIONS--
mbstring
--SKIPIF--
<?php
if (!function_exists('mb_regex_encoding')) die('skip No mbregex support');
?>
--FILE--
<?php
// iso-8859-11 is supported by Oniguruma but not by mbfl
mb_regex_encoding('iso-8859-11');
mb_ereg_search_init('x');
?>
--EXPECTF--
Fatal error: Uncaught ValueError: mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "iso-8859-11" given in %s:%d
Stack trace:
#0 %s(%d): mb_regex_encoding('iso-8859-11')
#1 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
/* Note that on Win32 CWD is per drive (heritage from CP/M).
* This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
*/
if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
if ((2 <= len) && isalpha((unsigned char)path[0]) && (':' == path[1])) {
/* Skip over the drive spec (if any) so as not to change */
path += 2;
len_adjust += 2;
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2883,8 +2883,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1,

len = MIN(len1, len2);
while (len--) {
c1 = zend_tolower((int)*(unsigned char *)s1++);
c2 = zend_tolower((int)*(unsigned char *)s2++);
c1 = zend_tolower((unsigned char)*(s1++));
c2 = zend_tolower((unsigned char)*(s2++));
if (c1 != c2) {
return c1 - c2;
}
Expand All @@ -2904,8 +2904,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1
}
len = MIN(length, MIN(len1, len2));
while (len--) {
c1 = zend_tolower((int)*(unsigned char *)s1++);
c2 = zend_tolower((int)*(unsigned char *)s2++);
c1 = zend_tolower((unsigned char)*(s1++));
c2 = zend_tolower((unsigned char)*(s2++));
if (c1 != c2) {
return c1 - c2;
}
Expand Down
10 changes: 5 additions & 5 deletions Zend/zend_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void virtual_cwd_main_cwd_init(uint8_t reinit) /* {{{ */
main_cwd_state.cwd_length = strlen(cwd);
#ifdef ZEND_WIN32
if (main_cwd_state.cwd_length >= 2 && cwd[1] == ':') {
cwd[0] = toupper(cwd[0]);
cwd[0] = toupper((unsigned char)cwd[0]);
}
#endif
main_cwd_state.cwd = strdup(cwd);
Expand Down Expand Up @@ -273,7 +273,7 @@ CWD_API char *virtual_getcwd_ex(size_t *length) /* {{{ */
*length = state->cwd_length+1;
retval = (char *) emalloc(*length+1);
memcpy(retval, state->cwd, *length);
retval[0] = toupper(retval[0]);
retval[0] = toupper((unsigned char)retval[0]);
retval[*length-1] = DEFAULT_SLASH;
retval[*length] = '\0';
return retval;
Expand Down Expand Up @@ -1114,21 +1114,21 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
if (resolved_path[start] == 0) {
goto verify;
}
resolved_path[start] = toupper(resolved_path[start]);
resolved_path[start] = toupper((unsigned char)resolved_path[start]);
start++;
}
resolved_path[start++] = DEFAULT_SLASH;
while (!IS_SLASH(resolved_path[start])) {
if (resolved_path[start] == 0) {
goto verify;
}
resolved_path[start] = toupper(resolved_path[start]);
resolved_path[start] = toupper((unsigned char)resolved_path[start]);
start++;
}
resolved_path[start++] = DEFAULT_SLASH;
} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
/* skip DRIVE name */
resolved_path[0] = toupper(resolved_path[0]);
resolved_path[0] = toupper((unsigned char)resolved_path[0]);
resolved_path[2] = DEFAULT_SLASH;
start = 3;
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_virtual_cwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef unsigned short mode_t;
#define IS_UNC_PATH(path, len) \
(len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1]))
#define IS_ABSOLUTE_PATH(path, len) \
(len >= 2 && (/* is local */isalpha(path[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
(len >= 2 && (/* is local */isalpha((unsigned char)(path)[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))

#else
#ifdef HAVE_DIRENT_H
Expand Down
4 changes: 2 additions & 2 deletions ext/com_dotnet/com_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ static PHP_INI_MH(OnTypeLibFileUpdate)
}

/* Remove leading/training white spaces on search_string */
while (isspace(*typelib_name)) {/* Ends on '\0' in worst case */
while (isspace((unsigned char)*typelib_name)) {/* Ends on '\0' in worst case */
typelib_name ++;
}
ptr = typelib_name + strlen(typelib_name) - 1;
while ((ptr != typelib_name) && isspace(*ptr)) {
while ((ptr != typelib_name) && isspace((unsigned char)*ptr)) {
*ptr = '\0';
ptr--;
}
Expand Down
10 changes: 5 additions & 5 deletions ext/date/lib/parse_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)

static void timelib_skip_day_suffix(const char **ptr)
{
if (isspace(**ptr)) {
if (isspace((unsigned char)**ptr)) {
return;
}
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
Expand Down Expand Up @@ -792,7 +792,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)

*tz_not_found = 1;

while (isdigit(**ptr) || **ptr == ':') {
while (isdigit((unsigned char)**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
Expand Down Expand Up @@ -857,7 +857,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
}

++*ptr;
while (isdigit(**ptr)) {
while (isdigit((unsigned char)**ptr)) {
++*ptr;
}

Expand Down Expand Up @@ -25936,10 +25936,10 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
in.errors->error_messages = NULL;

if (len > 0) {
while (isspace(*s) && s < e) {
while (isspace((unsigned char)*s) && s < e) {
s++;
}
while (isspace(*e) && e > s) {
while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
Expand Down
10 changes: 5 additions & 5 deletions ext/date/lib/parse_date.re
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)

static void timelib_skip_day_suffix(const char **ptr)
{
if (isspace(**ptr)) {
if (isspace((unsigned char)**ptr)) {
return;
}
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
Expand Down Expand Up @@ -790,7 +790,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)

*tz_not_found = 1;

while (isdigit(**ptr) || **ptr == ':') {
while (isdigit((unsigned char)**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
Expand Down Expand Up @@ -855,7 +855,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
}

++*ptr;
while (isdigit(**ptr)) {
while (isdigit((unsigned char)**ptr)) {
++*ptr;
}

Expand Down Expand Up @@ -1938,10 +1938,10 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
in.errors->error_messages = NULL;

if (len > 0) {
while (isspace(*s) && s < e) {
while (isspace((unsigned char)*s) && s < e) {
s++;
}
while (isspace(*e) && e > s) {
while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/date/lib/parse_iso_intervals.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,10 +948,10 @@ void timelib_strtointerval(const char *s, size_t len,
in.errors->error_messages = NULL;

if (len > 0) {
while (isspace(*s) && s < e) {
while (isspace((unsigned char)*s) && s < e) {
s++;
}
while (isspace(*e) && e > s) {
while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/date/lib/parse_iso_intervals.re
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ void timelib_strtointerval(const char *s, size_t len,
in.errors->error_messages = NULL;

if (len > 0) {
while (isspace(*s) && s < e) {
while (isspace((unsigned char)*s) && s < e) {
s++;
}
while (isspace(*e) && e > s) {
while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/date/lib/timelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void timelib_time_tz_abbr_update(timelib_time* tm, const char* tz_abbr)
TIMELIB_TIME_FREE(tm->tz_abbr);
tm->tz_abbr = timelib_strdup(tz_abbr);
for (i = 0; i < tz_abbr_len; i++) {
tm->tz_abbr[i] = toupper(tz_abbr[i]);
tm->tz_abbr[i] = toupper((unsigned char)tz_abbr[i]);
}
}

Expand Down
10 changes: 5 additions & 5 deletions ext/filter/logical_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,21 +528,21 @@ static int _php_filter_validate_domain(char * domain, size_t len, zend_long flag
}

/* First char must be alphanumeric */
if(*s == '.' || (hostname && !isalnum((int)*(unsigned char *)s))) {
if(*s == '.' || (hostname && !isalnum((unsigned char)*s))) {
return 0;
}

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

/* Reset label length counter */
i = 1;
} else {
if (i > 63 || (hostname && *s != '-' && !isalnum((int)*(unsigned char *)s))) {
if (i > 63 || (hostname && *s != '-' && !isalnum((unsigned char)*s))) {
return 0;
}

Expand All @@ -569,9 +569,9 @@ static int is_userinfo_valid(zend_string *str)
const char *valid = "-._~!$&'()*+,;=:";
const char *p = ZSTR_VAL(str);
while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) {
if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) {
if (isalpha((unsigned char)*p) || isdigit((unsigned char)*p) || strchr(valid, *p)) {
p++;
} else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) {
} else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit((unsigned char)p[1]) && isxdigit((unsigned char)p[2])) {
p += 3;
} else {
return 0;
Expand Down
10 changes: 5 additions & 5 deletions ext/ftp/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value
array_init(return_value);
while (ftp_readline(ftp)) {
add_next_index_string(return_value, ftp->inbuf);
if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
if (isdigit((unsigned char)ftp->inbuf[0]) && isdigit((unsigned char)ftp->inbuf[1]) && isdigit((unsigned char)ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
return;
}
}
Expand Down Expand Up @@ -841,7 +841,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
return 0;
}
/* parse out the IP and port */
for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
for (ptr = ftp->inbuf; *ptr && !isdigit((unsigned char)*ptr); ptr++);
n = sscanf(ptr, "%lu,%lu,%lu,%lu,%lu,%lu", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]);
if (n != 6) {
return 0;
Expand Down Expand Up @@ -1144,7 +1144,7 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len)
return -1;
}
/* parse out the timestamp */
for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
for (ptr = ftp->inbuf; *ptr && !isdigit((unsigned char)*ptr); ptr++);
n = sscanf(ptr, "%4u%2u%2u%2u%2u%2u", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
if (n != 6) {
return -1;
Expand Down Expand Up @@ -1342,13 +1342,13 @@ ftp_getresp(ftpbuf_t *ftp)
}

/* Break out when the end-tag is found */
if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
if (isdigit((unsigned char)ftp->inbuf[0]) && isdigit((unsigned char)ftp->inbuf[1]) && isdigit((unsigned char)ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
break;
}
}

/* translate the tag */
if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) {
if (!isdigit((unsigned char)ftp->inbuf[0]) || !isdigit((unsigned char)ftp->inbuf[1]) || !isdigit((unsigned char)ftp->inbuf[2])) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/gd/libgd/gd_xbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
} else {
for (i=0; i<l; i++) {
/* only in C-locale isalnum() would work */
if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
if (!isupper((unsigned char)name[i]) && !islower((unsigned char)name[i]) && !isdigit((unsigned char)name[i])) {
name[i] = '_';
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2316,7 +2316,7 @@ PHP_FUNCTION(imap_utf8)
#define SPECIAL(c) ((c) <= 0x1f || (c) >= 0x7f)

/* validate a modified-base64 character */
#define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == ',')
#define B64CHAR(c) (isalnum((unsigned char)(c)) || (c) == '+' || (c) == ',')

/* map the low 64 bits of `n' to the modified-base64 characters */
#define B64(n) ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/locale/locale_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ static int strToMatch(const char* str ,char *retstr)
if( *str == '-' ){
*retstr = '_';
} else {
*retstr = tolower(*str);
*retstr = tolower((unsigned char)*str);
}
str++;
retstr++;
Expand Down
4 changes: 2 additions & 2 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ static char *php_mb_rfc1867_getword(const zend_encoding *encoding, char **line,

static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *str) /* {{{ */
{
while (*str && isspace(*(unsigned char *)str)) {
while (*str && isspace((unsigned char)*str)) {
++str;
}

Expand All @@ -642,7 +642,7 @@ static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *st
} else {
char *strend = str;

while (*strend && !isspace(*(unsigned char *)strend)) {
while (*strend && !isspace((unsigned char)*strend)) {
++strend;
}
return php_mb_rfc1867_substring_conf(encoding, str, strend - str, 0);
Expand Down
9 changes: 7 additions & 2 deletions ext/mbstring/php_mbregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,13 @@ int php_mb_regex_set_mbctype(const char *encname)
if (mbctype == ONIG_ENCODING_UNDEF) {
return FAILURE;
}
const mbfl_encoding *mbfl_enc = mbfl_name2encoding(encname);
if (mbfl_enc == NULL) {
/* Encoding supported by Oniguruma but not by mbfl */
return FAILURE;
}
MBREX(current_mbctype) = mbctype;
MBREX(current_mbctype_mbfl_encoding) = mbfl_name2encoding(encname);
MBREX(current_mbctype_mbfl_encoding) = mbfl_enc;
return SUCCESS;
}
/* }}} */
Expand Down Expand Up @@ -779,7 +784,7 @@ static inline void mb_regex_substitute(
continue;
}
if (name_end[0] == delim) break;
if (maybe_num && !isdigit(name_end[0])) maybe_num = 0;
if (maybe_num && !isdigit((unsigned char)name_end[0])) maybe_num = 0;
name_end++;
}
p = name_end + 1;
Expand Down
Loading
Loading