]> granicus.if.org Git - php/commitdiff
Add macro to get ini target address
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 27 Apr 2020 08:21:26 +0000 (10:21 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 27 Apr 2020 08:30:00 +0000 (10:30 +0200)
Zend/zend.c
Zend/zend_ini.c
Zend/zend_ini.h
ext/opcache/zend_accelerator_module.c
ext/soap/soap.c
ext/zlib/zlib.c
main/fopen_wrappers.c

index 555483a7be25a5c10cad8b34bbcda928c7ab0dc2..40dd8991a1ea00e7cc2ad30bfba397efbdfe527a 100644 (file)
@@ -139,18 +139,9 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
 
 static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
 {
-       zend_long *p, val;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (zend_long *) (base+(size_t) mh_arg1);
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
 
-       val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
+       zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
 
        if (stage != ZEND_INI_STAGE_STARTUP &&
            stage != ZEND_INI_STAGE_SHUTDOWN &&
index a2344653bc4b00f673e35d27b13c566c35daa14d..279dcae03c931f23e56cd20cfaca7b5919cc3bd0 100644 (file)
@@ -578,17 +578,7 @@ ZEND_INI_DISP(display_link_numbers) /* {{{ */
 /* Standard message handlers */
 ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
 {
-       zend_bool *p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (zend_bool *) (base+(size_t) mh_arg1);
-
+       zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR();
        *p = zend_ini_parse_bool(new_value);
        return SUCCESS;
 }
@@ -596,17 +586,7 @@ ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
 
 ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
 {
-       zend_long *p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (zend_long *) (base+(size_t) mh_arg1);
-
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
        *p = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
        return SUCCESS;
 }
@@ -614,21 +594,12 @@ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
 
 ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
 {
-       zend_long *p, tmp;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
+       zend_long tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
        if (tmp < 0) {
                return FAILURE;
        }
 
-       p = (zend_long *) (base+(size_t) mh_arg1);
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
        *p = tmp;
 
        return SUCCESS;
@@ -637,17 +608,7 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
 
 ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
 {
-       double *p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (double *) (base+(size_t) mh_arg1);
-
+       double *p = (double *) ZEND_INI_GET_ADDR();
        *p = zend_strtod(ZSTR_VAL(new_value), NULL);
        return SUCCESS;
 }
@@ -655,17 +616,7 @@ ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
 
 ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */
 {
-       char **p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (char **) (base+(size_t) mh_arg1);
-
+       char **p = (char **) ZEND_INI_GET_ADDR();
        *p = new_value ? ZSTR_VAL(new_value) : NULL;
        return SUCCESS;
 }
@@ -673,21 +624,11 @@ ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */
 
 ZEND_API ZEND_INI_MH(OnUpdateStringUnempty) /* {{{ */
 {
-       char **p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
        if (new_value && !ZSTR_VAL(new_value)[0]) {
                return FAILURE;
        }
 
-       p = (char **) (base+(size_t) mh_arg1);
-
+       char **p = (char **) ZEND_INI_GET_ADDR();
        *p = new_value ? ZSTR_VAL(new_value) : NULL;
        return SUCCESS;
 }
index 3759ca319618c542902987b39ed31b7501d1a32f..0289b322be1a261ab499ba6cf76e93ce1315f1fd 100644 (file)
@@ -194,4 +194,12 @@ typedef struct _zend_ini_parser_param {
        void *arg;
 } zend_ini_parser_param;
 
+#ifndef ZTS
+# define ZEND_INI_GET_BASE() ((char *) mh_arg2)
+#else
+# define ZEND_INI_GET_BASE() ((char *) ts_resource(*((int *) mh_arg2)))
+#endif
+
+#define ZEND_INI_GET_ADDR() (ZEND_INI_GET_BASE() + (size_t) mh_arg1)
+
 #endif /* ZEND_INI_H */
index ef3cb5cc5c473e66d1ac9e798bf46ca6d323a51d..da9806db7f1e146dc82731dd099787d549e0ed24 100644 (file)
@@ -63,19 +63,8 @@ static int validate_api_restriction(void)
 
 static ZEND_INI_MH(OnUpdateMemoryConsumption)
 {
-       zend_long *p;
-       zend_long memsize;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       /* keep the compiler happy */
-       (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
-
-       p = (zend_long *) (base + (size_t)mh_arg1);
-       memsize = atoi(ZSTR_VAL(new_value));
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
+       zend_long memsize = atoi(ZSTR_VAL(new_value));
        /* sanity check we must use at least 8 MB */
        if (memsize < 8) {
                const char *new_new_value = "8";
@@ -103,19 +92,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
 
 static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
 {
-       zend_long *p;
-       zend_long size;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       /* keep the compiler happy */
-       (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
-
-       p = (zend_long *) (base + (size_t)mh_arg1);
-       size = atoi(ZSTR_VAL(new_value));
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
+       zend_long size = atoi(ZSTR_VAL(new_value));
        /* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
 
        if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) {
@@ -147,19 +125,8 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
 
 static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
 {
-       double *p;
-       zend_long percentage;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       /* keep the compiler happy */
-       (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
-
-       p = (double *) (base + (size_t)mh_arg1);
-       percentage = atoi(ZSTR_VAL(new_value));
+       double *p = (double *) ZEND_INI_GET_ADDR();
+       zend_long percentage = atoi(ZSTR_VAL(new_value));
 
        if (percentage <= 0 || percentage > 50) {
                const char *new_new_value = "5";
@@ -187,14 +154,7 @@ static ZEND_INI_MH(OnEnable)
                return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
        } else {
                /* It may be only temporary disabled */
-               zend_bool *p;
-#ifndef ZTS
-               char *base = (char *) mh_arg2;
-#else
-               char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-               p = (zend_bool *) (base+(size_t) mh_arg1);
+               zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR();
                if ((ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) ||
                    (ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) ||
                    (ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) ||
index 2c82ac3919a4057424f5441048c6f4919aab49d7..a93813e9d186999b189ca93b8b7966e6fe8e92dc 100644 (file)
@@ -211,17 +211,8 @@ ZEND_GET_MODULE(soap)
 
 ZEND_INI_MH(OnUpdateCacheMode)
 {
-       char *p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (char*) (base+(size_t) mh_arg1);
-
+       char *p = (char *) ZEND_INI_GET_ADDR();
        *p = (char)atoi(ZSTR_VAL(new_value));
-
        return SUCCESS;
 }
 
index 99a1f14b2bf4cf9369b57f9989009839b8d2f39b..6951c155ad7ba0db4671ff0f5cc100b294b723ce 100644 (file)
@@ -1250,15 +1250,6 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
 {
        int int_value;
        char *ini_value;
-       zend_long *p;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base;
-
-       base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
        if (new_value == NULL) {
                return FAILURE;
        }
@@ -1284,7 +1275,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
                }
        }
 
-       p = (zend_long *) (base+(size_t) mh_arg1);
+       zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
        *p = int_value;
 
        ZLIBG(output_compression) = ZLIBG(output_compression_default);
index b2d698e7b0050a613209965d6aa1d269618233dd..d61a7c689397ec071fda877c088c35efbbef6f99 100644 (file)
@@ -73,14 +73,8 @@ Allows any change to open_basedir setting in during Startup and Shutdown events,
 or a tightening during activation/runtime/deactivation */
 PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
 {
-       char **p, *pathbuf, *ptr, *end;
-#ifndef ZTS
-       char *base = (char *) mh_arg2;
-#else
-       char *base = (char *) ts_resource(*((int *) mh_arg2));
-#endif
-
-       p = (char **) (base + (size_t) mh_arg1);
+       char **p = (char **) ZEND_INI_GET_ADDR();
+       char *pathbuf, *ptr, *end;
 
        if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE) {
                /* We're in a PHP_INI_SYSTEM context, no restrictions */