@@ -165,7 +165,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
165
165
int is_letter = ((unsigned int ) ((l - 'A' ) ^ (l - 'F' - 1 ))) >> (8 * sizeof (unsigned int ) - 1 );
166
166
unsigned char d ;
167
167
168
- /* basically (c >= '0' && c <= '9') || (l >= 'A' && l <= 'F') */
168
+ /* basically (c >= '0' && c <= '9') || (l >= 'A' && l <= 'F') */
169
169
if (EXPECTED ((((c ^ '0' ) - 10 ) >> (8 * sizeof (unsigned int ) - 1 )) | is_letter )) {
170
170
d = (l - 0x10 - 0x27 * is_letter ) << 4 ;
171
171
} else {
@@ -2381,7 +2381,11 @@ PHP_FUNCTION(substr)
2381
2381
}
2382
2382
}
2383
2383
2384
- if ((f + l ) > (zend_long )ZSTR_LEN (str )) {
2384
+ if (f > (zend_long )ZSTR_LEN (str )) {
2385
+ RETURN_FALSE ;
2386
+ }
2387
+
2388
+ if ((size_t )l > ZSTR_LEN (str ) - (size_t )f ) {
2385
2389
l = ZSTR_LEN (str ) - f ;
2386
2390
}
2387
2391
@@ -2854,7 +2858,7 @@ PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size
2854
2858
for (i = 0 ; i < trlen ; i ++ ) {
2855
2859
xlat [(size_t )(unsigned char ) str_from [i ]] = str_to [i ];
2856
2860
}
2857
-
2861
+
2858
2862
for (i = 0 ; i < len ; i ++ ) {
2859
2863
str [i ] = xlat [(size_t )(unsigned char ) str [i ]];
2860
2864
}
@@ -3247,7 +3251,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, char *lc_haystack
3247
3251
zend_string_release (lc_needle );
3248
3252
goto nothing_todo ;
3249
3253
}
3250
-
3254
+
3251
3255
if (str_len > ZSTR_LEN (lc_needle )) {
3252
3256
new_str = zend_string_safe_alloc (count , str_len - ZSTR_LEN (lc_needle ), ZSTR_LEN (haystack ), 0 );
3253
3257
} else {
@@ -3410,7 +3414,7 @@ PHP_FUNCTION(strtr)
3410
3414
ZVAL_LONG (& tmp , num_key );
3411
3415
convert_to_string (& tmp );
3412
3416
str_key = Z_STR (tmp );
3413
- }
3417
+ }
3414
3418
replace = zval_get_string (entry );
3415
3419
if (ZSTR_LEN (str_key ) < 1 ) {
3416
3420
RETVAL_STR_COPY (str );
@@ -3973,7 +3977,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s
3973
3977
zend_string_release (lc_subject_str );
3974
3978
lc_subject_str = NULL ;
3975
3979
}
3976
- }
3980
+ }
3977
3981
}
3978
3982
3979
3983
zend_string_release (search_str );
0 commit comments