Skip to content

Commit d1d002f

Browse files
committed
Fix bug #73648 - integer overflow in substr
1 parent 6736527 commit d1d002f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/standard/string.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
165165
int is_letter = ((unsigned int) ((l - 'A') ^ (l - 'F' - 1))) >> (8 * sizeof(unsigned int) - 1);
166166
unsigned char d;
167167

168-
/* basically (c >= '0' && c <= '9') || (l >= 'A' && l <= 'F') */
168+
/* basically (c >= '0' && c <= '9') || (l >= 'A' && l <= 'F') */
169169
if (EXPECTED((((c ^ '0') - 10) >> (8 * sizeof(unsigned int) - 1)) | is_letter)) {
170170
d = (l - 0x10 - 0x27 * is_letter) << 4;
171171
} else {
@@ -2371,7 +2371,7 @@ PHP_FUNCTION(substr)
23712371
RETURN_FALSE;
23722372
}
23732373

2374-
if ((f + l) > (zend_long)ZSTR_LEN(str)) {
2374+
if ((size_t)l > ZSTR_LEN(str) - (size_t)f) {
23752375
l = ZSTR_LEN(str) - f;
23762376
}
23772377

@@ -2842,7 +2842,7 @@ PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size
28422842
for (i = 0; i < trlen; i++) {
28432843
xlat[(size_t)(unsigned char) str_from[i]] = str_to[i];
28442844
}
2845-
2845+
28462846
for (i = 0; i < len; i++) {
28472847
str[i] = xlat[(size_t)(unsigned char) str[i]];
28482848
}
@@ -3235,7 +3235,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, char *lc_haystack
32353235
zend_string_release(lc_needle);
32363236
goto nothing_todo;
32373237
}
3238-
3238+
32393239
if (str_len > ZSTR_LEN(lc_needle)) {
32403240
new_str = zend_string_safe_alloc(count, str_len - ZSTR_LEN(lc_needle), ZSTR_LEN(haystack), 0);
32413241
} else {
@@ -3398,7 +3398,7 @@ PHP_FUNCTION(strtr)
33983398
ZVAL_LONG(&tmp, num_key);
33993399
convert_to_string(&tmp);
34003400
str_key = Z_STR(tmp);
3401-
}
3401+
}
34023402
replace = zval_get_string(entry);
34033403
if (ZSTR_LEN(str_key) < 1) {
34043404
RETVAL_STR_COPY(str);
@@ -3961,7 +3961,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s
39613961
zend_string_release(lc_subject_str);
39623962
lc_subject_str = NULL;
39633963
}
3964-
}
3964+
}
39653965
}
39663966

39673967
zend_string_release(search_str);

0 commit comments

Comments
 (0)