Commit 50e5acdd4ba for php

commit 50e5acdd4baea66a11ff307ca26cecad7b40d4c3
Merge: 4adae1c2655 cd16f66d331
Author: David Carlier <devnexen@gmail.com>
Date:   Sun Nov 29 12:23:42 2026 +0000

    Merge branch 'PHP-8.5' into PHP-8.6

    * PHP-8.5:
      ext/intl: Fix NULL deref in locale_parse() and locale_get_all_variants()

    # Conflicts:
    #       ext/intl/locale/locale_methods.cpp

diff --cc ext/intl/locale/locale_methods.cpp
index 4febdf0f9ec,d3df381c11e..37b3407c33e
--- a/ext/intl/locale/locale_methods.cpp
+++ b/ext/intl/locale/locale_methods.cpp
@@@ -1189,19 -1074,23 +1189,21 @@@ static int add_array_entry(const char*
  	if( (strcmp(key_name , LOC_PRIVATE_TAG)==0) ||
  		( strcmp(key_name , LOC_VARIANT_TAG)==0) ){
  		if( result > 0 && key_value){
- 			int cnt = 0;
  			/* Tokenize on the "_" or "-"  */
  			token = php_strtok_r( key_value->val , DELIMITER ,&last_ptr);
- 			/* Over-allocates a few bytes for the integer so we don't have to reallocate. */
- 			size_t cur_key_name_size = (sizeof("-2147483648") - 1) + strlen(key_name) + 1;
- 			cur_key_name.reset(reinterpret_cast<char *>(emalloc(cur_key_name_size)));
- 			char *p_cur_key_name = cur_key_name.get();
- 			snprintf( p_cur_key_name, cur_key_name_size , "%s%d", key_name , cnt++);
- 			add_assoc_string( hash_arr, p_cur_key_name , token);
- 			/* tokenize on the "_" or "-" and stop  at singleton if any */
- 			while( (token = php_strtok_r(nullptr , DELIMITER , &last_ptr)) && (strlen(token)>1) ){
- 				snprintf( p_cur_key_name , cur_key_name_size, "%s%d", key_name , cnt++);
+ 			if (token) {
+ 				int cnt = 0;
 -				if( cur_key_name ){
 -					efree( cur_key_name);
 -				}
+ 				/* Over-allocates a few bytes for the integer so we don't have to reallocate. */
+ 				size_t cur_key_name_size = (sizeof("-2147483648") - 1) + strlen(key_name) + 1;
 -				cur_key_name = reinterpret_cast<char *>(emalloc(cur_key_name_size));
 -				snprintf( cur_key_name, cur_key_name_size , "%s%d", key_name , cnt++);
 -				add_assoc_string( hash_arr, cur_key_name , token);
++				cur_key_name.reset(reinterpret_cast<char *>(emalloc(cur_key_name_size)));
++				char *p_cur_key_name = cur_key_name.get();
++				snprintf( p_cur_key_name, cur_key_name_size , "%s%d", key_name , cnt++);
 +				add_assoc_string( hash_arr, p_cur_key_name , token);
+ 				/* tokenize on the "_" or "-" and stop  at singleton if any */
 -				while( (token = php_strtok_r(NULL , DELIMITER , &last_ptr)) && (strlen(token)>1) ){
 -					snprintf( cur_key_name , cur_key_name_size, "%s%d", key_name , cnt++);
 -					add_assoc_string( hash_arr, cur_key_name , token);
++				while( (token = php_strtok_r(nullptr , DELIMITER , &last_ptr)) && (strlen(token)>1) ){
++					snprintf( p_cur_key_name , cur_key_name_size, "%s%d", key_name , cnt++);
++					add_assoc_string( hash_arr, p_cur_key_name , token);
+ 				}
  			}
  /*
  			if( strcmp(key_name, LOC_PRIVATE_TAG) == 0 ){
@@@ -1292,10 -1189,12 +1294,12 @@@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(loca
  		if( result > 0 && variant){
  			/* Tokenize on the "_" or "-" */
  			token = php_strtok_r( variant->val , DELIMITER , &saved_ptr);
- 			add_next_index_stringl( return_value, token , strlen(token));
- 			/* tokenize on the "_" or "-" and stop  at singleton if any	*/
- 			while( (token = php_strtok_r(nullptr , DELIMITER, &saved_ptr)) && (strlen(token)>1) ){
+ 			if (token) {
  				add_next_index_stringl( return_value, token , strlen(token));
+ 				/* tokenize on the "_" or "-" and stop  at singleton if any	*/
 -				while( (token = php_strtok_r(NULL , DELIMITER, &saved_ptr)) && (strlen(token)>1) ){
++				while( (token = php_strtok_r(nullptr , DELIMITER, &saved_ptr)) && (strlen(token)>1) ){
+ 					add_next_index_stringl( return_value, token , strlen(token));
+ 				}
  			}
  		}
  		if( variant ){