@@ -192,43 +192,35 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
192
192
return result ;
193
193
}
194
194
195
- static void php_head_parse_cookie_options_array (zval * options , zend_long * expires , zend_string * * path , zend_string * * domain , zend_bool * secure , zend_bool * httponly , zend_string * * samesite ) {
196
- int found = 0 ;
195
+ static zend_result php_head_parse_cookie_options_array (zval * options , zend_long * expires , zend_string * * path ,
196
+ zend_string * * domain , zend_bool * secure , zend_bool * httponly , zend_string * * samesite )
197
+ {
197
198
zend_string * key ;
198
199
zval * value ;
199
200
200
201
ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (options ), key , value ) {
201
- if (key ) {
202
- if (zend_string_equals_literal_ci (key , "expires" )) {
203
- * expires = zval_get_long (value );
204
- found ++ ;
205
- } else if (zend_string_equals_literal_ci (key , "path" )) {
206
- * path = zval_get_string (value );
207
- found ++ ;
208
- } else if (zend_string_equals_literal_ci (key , "domain" )) {
209
- * domain = zval_get_string (value );
210
- found ++ ;
211
- } else if (zend_string_equals_literal_ci (key , "secure" )) {
212
- * secure = zval_is_true (value );
213
- found ++ ;
214
- } else if (zend_string_equals_literal_ci (key , "httponly" )) {
215
- * httponly = zval_is_true (value );
216
- found ++ ;
217
- } else if (zend_string_equals_literal_ci (key , "samesite" )) {
218
- * samesite = zval_get_string (value );
219
- found ++ ;
220
- } else {
221
- php_error_docref (NULL , E_WARNING , "Unrecognized key '%s' found in the options array" , ZSTR_VAL (key ));
222
- }
202
+ if (!key ) {
203
+ zend_value_error ("%s(): option array cannot have numeric keys" , get_active_function_name ());
204
+ return FAILURE ;
205
+ }
206
+ if (zend_string_equals_literal_ci (key , "expires" )) {
207
+ * expires = zval_get_long (value );
208
+ } else if (zend_string_equals_literal_ci (key , "path" )) {
209
+ * path = zval_get_string (value );
210
+ } else if (zend_string_equals_literal_ci (key , "domain" )) {
211
+ * domain = zval_get_string (value );
212
+ } else if (zend_string_equals_literal_ci (key , "secure" )) {
213
+ * secure = zval_is_true (value );
214
+ } else if (zend_string_equals_literal_ci (key , "httponly" )) {
215
+ * httponly = zval_is_true (value );
216
+ } else if (zend_string_equals_literal_ci (key , "samesite" )) {
217
+ * samesite = zval_get_string (value );
223
218
} else {
224
- php_error_docref (NULL , E_WARNING , "Numeric key found in the options array" );
219
+ zend_value_error ("%s(): option \"%s\" is invalid" , get_active_function_name (), ZSTR_VAL (key ));
220
+ return FAILURE ;
225
221
}
226
222
} ZEND_HASH_FOREACH_END ();
227
-
228
- /* Array is not empty but no valid keys were found */
229
- if (found == 0 && zend_hash_num_elements (Z_ARRVAL_P (options )) > 0 ) {
230
- php_error_docref (NULL , E_WARNING , "No valid options were found in the given array" );
231
- }
223
+ return SUCCESS ;
232
224
}
233
225
234
226
static void php_setcookie_common (INTERNAL_FUNCTION_PARAMETERS , bool is_raw )
@@ -257,22 +249,23 @@ static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw)
257
249
"($expires_or_options) is an array" , get_active_function_name ());
258
250
RETURN_THROWS ();
259
251
}
260
- php_head_parse_cookie_options_array (expires_or_options , & expires , & path ,
261
- & domain , & secure , & httponly , & samesite );
252
+ if (FAILURE == php_head_parse_cookie_options_array (expires_or_options , & expires , & path ,
253
+ & domain , & secure , & httponly , & samesite )) {
254
+ goto cleanup ;
255
+ }
262
256
} else {
263
257
expires = zval_get_long (expires_or_options );
264
258
}
265
259
}
266
260
267
- if (!EG (exception )) {
268
- if (php_setcookie (name , value , expires , path , domain , secure , httponly , samesite , !is_raw ) == SUCCESS ) {
269
- RETVAL_TRUE ;
270
- } else {
271
- RETVAL_FALSE ;
272
- }
261
+ if (php_setcookie (name , value , expires , path , domain , secure , httponly , samesite , !is_raw ) == SUCCESS ) {
262
+ RETVAL_TRUE ;
263
+ } else {
264
+ RETVAL_FALSE ;
273
265
}
274
266
275
267
if (expires_or_options && Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
268
+ cleanup :
276
269
if (path ) {
277
270
zend_string_release (path );
278
271
}
0 commit comments