]> granicus.if.org Git - php/commitdiff
Fix static property indirections in file cache
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 20 May 2020 08:55:36 +0000 (10:55 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 20 May 2020 09:12:18 +0000 (11:12 +0200)
If the class is already linked, we need to serialize and
unserialize INDIRECTed static properties. Normally these would
be set up when copying from cache.

ext/opcache/zend_file_cache.c

index 18c69288b3319fd82c2232052600ce0704ba24c5..b46edcb0650eb84c32cd0e8a3b2c460e97ceefee 100644 (file)
@@ -368,6 +368,10 @@ static void zend_file_cache_serialize_zval(zval                     *zv,
                                zend_file_cache_serialize_ast(GC_AST(ast), script, info, buf);
                        }
                        break;
+               case IS_INDIRECT:
+                       /* Used by static properties. */
+                       SERIALIZE_PTR(Z_INDIRECT_P(zv));
+                       break;
        }
 }
 
@@ -626,7 +630,6 @@ static void zend_file_cache_serialize_class(zval                     *zv,
                                             void                     *buf)
 {
        zend_class_entry *ce;
-       zend_class_entry *parent = NULL;
 
        SERIALIZE_PTR(Z_PTR_P(zv));
        ce = Z_PTR_P(zv);
@@ -637,7 +640,6 @@ static void zend_file_cache_serialize_class(zval                     *zv,
                if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
                        SERIALIZE_STR(ce->parent_name);
                } else {
-                       parent = ce->parent;
                        SERIALIZE_PTR(ce->parent);
                }
        }
@@ -655,16 +657,13 @@ static void zend_file_cache_serialize_class(zval                     *zv,
                }
        }
        if (ce->default_static_members_table) {
-               zval *table, *p, *end;
+               zval *p, *end;
 
                SERIALIZE_PTR(ce->default_static_members_table);
-               table = ce->default_static_members_table;
-               UNSERIALIZE_PTR(table);
+               p = ce->default_static_members_table;
+               UNSERIALIZE_PTR(p);
 
-               /* Serialize only static properties in this class.
-                * Static properties from parent classes will be handled in class_copy_ctor */
-               p = table + (parent ? parent->default_static_members_count : 0);
-               end = table + ce->default_static_members_count;
+               end = p + ce->default_static_members_count;
                while (p < end) {
                        zend_file_cache_serialize_zval(p, script, info, buf);
                        p++;
@@ -1081,6 +1080,10 @@ static void zend_file_cache_unserialize_zval(zval                    *zv,
                                zend_file_cache_unserialize_ast(Z_ASTVAL_P(zv), script, buf);
                        }
                        break;
+               case IS_INDIRECT:
+                       /* Used by static properties. */
+                       UNSERIALIZE_PTR(Z_INDIRECT_P(zv));
+                       break;
        }
 }
 
@@ -1325,7 +1328,6 @@ static void zend_file_cache_unserialize_class(zval                    *zv,
                                               void                    *buf)
 {
        zend_class_entry *ce;
-       zend_class_entry *parent = NULL;
 
        UNSERIALIZE_PTR(Z_PTR_P(zv));
        ce = Z_PTR_P(zv);
@@ -1336,7 +1338,6 @@ static void zend_file_cache_unserialize_class(zval                    *zv,
                        UNSERIALIZE_STR(ce->parent_name);
                } else {
                        UNSERIALIZE_PTR(ce->parent);
-                       parent = ce->parent;
                }
        }
        zend_file_cache_unserialize_hash(&ce->function_table,
@@ -1353,14 +1354,10 @@ static void zend_file_cache_unserialize_class(zval                    *zv,
                }
        }
        if (ce->default_static_members_table) {
-               zval *table, *p, *end;
-
-               /* Unserialize only static properties in this class.
-                * Static properties from parent classes will be handled in class_copy_ctor */
+               zval *p, *end;
                UNSERIALIZE_PTR(ce->default_static_members_table);
-               table = ce->default_static_members_table;
-               p = table + (parent ? parent->default_static_members_count : 0);
-               end = table + ce->default_static_members_count;
+               p = ce->default_static_members_table;
+               end = p + ce->default_static_members_count;
                while (p < end) {
                        zend_file_cache_unserialize_zval(p, script, buf);
                        p++;