]> granicus.if.org Git - php/commitdiff
Cheaper checking
authorXinchen Hui <laruence@gmail.com>
Fri, 17 Aug 2018 07:21:48 +0000 (15:21 +0800)
committerXinchen Hui <laruence@gmail.com>
Fri, 17 Aug 2018 07:21:48 +0000 (15:21 +0800)
ext/standard/head.c

index c202e8f9523ba2c2b09053ee4f87e7d2a7eae03d..07b9a93cf2ae8439774cac7863a79af6025ad21a 100644 (file)
@@ -206,17 +206,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
        return result;
 }
 
-static int 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) {
+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) {
        int found = 0;
        zend_string *key;
        zval *value;
 
-       if (*path) {
-               *path = NULL;
-               php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
-               return 0;
-       }
-
        ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), key, value) {
                if (key) {
                        if (zend_string_equals_literal_ci(key, "expires")) {
@@ -249,8 +243,6 @@ static int php_head_parse_cookie_options_array(zval *options, zend_long *expires
        if (found == 0 && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0) {
                php_error_docref(NULL, E_WARNING, "No valid options were found in the given array");
        }
-
-       return 1;
 }
 
 /* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure[, bool httponly]]]]]])
@@ -276,10 +268,11 @@ PHP_FUNCTION(setcookie)
 
        if (expires_or_options) {
                if (Z_TYPE_P(expires_or_options) == IS_ARRAY) {
-                       if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) {
-                               RETVAL_FALSE;
-                               goto cleanup;
+                       if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) {
+                               php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
+                               RETURN_FALSE;
                        }
+                       php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite);
                } else {
                        expires = zval_get_long(expires_or_options);
                }
@@ -291,7 +284,6 @@ PHP_FUNCTION(setcookie)
                RETVAL_FALSE;
        }
 
-cleanup:
        if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) {
                if (path) {
                        zend_string_release(path);
@@ -314,7 +306,7 @@ PHP_FUNCTION(setrawcookie)
        zval *expires_or_options = NULL;
        zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL;
        zend_long expires = 0;
-       zend_bool secure = 0, httponly = 0, options_array = 0;
+       zend_bool secure = 0, httponly = 0;
 
        ZEND_PARSE_PARAMETERS_START(1, 7)
                Z_PARAM_STR(name)
@@ -329,11 +321,11 @@ PHP_FUNCTION(setrawcookie)
 
        if (expires_or_options) {
                if (Z_TYPE_P(expires_or_options) == IS_ARRAY) {
-                       options_array = 1;
-                       if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) {
-                               RETVAL_FALSE;
-                               goto cleanup;
+                       if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) {
+                               php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
+                               RETURN_FALSE;
                        }
+                       php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite);
                } else {
                        expires = Z_LVAL_P(expires_or_options);
                }
@@ -345,8 +337,7 @@ PHP_FUNCTION(setrawcookie)
                RETVAL_FALSE;
        }
 
-cleanup:
-       if (options_array) {
+       if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) {
                if (path) {
                        zend_string_release(path);
                }