Bug #77339 [Opn->Ver]: __callStatic may get incorrect arguments

From: Date: Sun, 23 Dec 2018 14:20:52 +0000
Subject: Bug #77339 [Opn->Ver]: __callStatic may get incorrect arguments
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218584@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77339&edit=1

 ID:                 77339
 Updated by:         cmb@php.net
 Reported by:        php at zsxsoft dot com
 Summary:            __callStatic may get incorrect arguments
-Status:             Open
+Status:             Verified
 Type:               Bug
-Package:            Class/Object related
+Package:            Scripting Engine problem
 Operating System:   macOS 10.14.2
 PHP Version:        7.3.0
-Assigned To:        
+Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

This regression is caused by commit d1d1aff[1].  Dmitry, could you
please have a look at this issue?

[1] <http://git.php.net/?p=php-src.git;a=commit;h=d1d1aff4e54a014d3d3693fe4505517226402eea>


Previous Comments:
------------------------------------------------------------------------
[2018-12-23 02:02:53] php at zsxsoft dot com

Description:
------------
This only happened in PHP 7.3.

Test script followed. $arguments should be ['getSomeWhat'], but __callStatic get [?] here.

I checked *myht->arData, $arguments[0] got a wrong type.

The normal one, you can see type = 0x6:

    (_zval_struct::(anonymous union)) u1 = {
      (_zval_struct::(anonymous struct)) v = {
        (zend_uchar) type = '\x06'
        (zend_uchar) type_flags = '\x01'
        (_zval_struct::(anonymous union)) u = {
          (uint16_t) call_info = 0
          (uint16_t) extra = 0
        }
      }
      (uint32_t) type_info = 262
    }

(lldb) fr v --show-types *myht->arData->val.value.str
(zend_string) *myht->arData->val.value.str = {
  (zend_refcounted_h) gc = {
    (uint32_t) refcount = 1
    (_zend_refcounted_h::(anonymous union)) u = {
      (uint32_t) type_info = 6
    }
  }
  (zend_ulong) h = 0
  (size_t) len = 6
  (char [1]) val = "aaazzz"
}

The __callStatic's argument, you can see data is normal but type is not initialized.

    (_zval_struct::(anonymous union)) u1 = {
      (_zval_struct::(anonymous struct)) v = {
        (zend_uchar) type = '\0'
        (zend_uchar) type_flags = '\0'
        (_zval_struct::(anonymous union)) u = {
          (uint16_t) call_info = 0
          (uint16_t) extra = 0
        }
      }
      (uint32_t) type_info = 0
    }
    (_zval_struct::(anonymous union)) u2 = {
      (uint32_t) next = 4294967295
      (uint32_t) cache_slot = 4294967295
      (uint32_t) opline_num = 4294967295
      (uint32_t) lineno = 4294967295
      (uint32_t) num_args = 4294967295
      (uint32_t) fe_pos = 4294967295
      (uint32_t) fe_iter_idx = 4294967295
      (uint32_t) access_flags = 4294967295
      (uint32_t) property_guard = 4294967295
      (uint32_t) constant_flags = 4294967295
      (uint32_t) extra = 4294967295
    }


Test script:
---------------
<?php
class Foo
{
    static function __callStatic($name, $arguments) {
        if ($name === 'get') {
            if (!isset($arguments[0])) {
                var_dump(['getSomeWhat']);
                var_dump($arguments);
                exit;
            }
        } 
        echo 'OK';
    }

    protected function get ($key) {
        // BUG!!!
    }
}

class Bar
{
    static function __callStatic($name, $arguments) {
        echo Foo::get('getSomeWhat');
    }
}

Bar::someUndefinedStaticFunction();

Expected result:
----------------
OK

Actual result:
--------------
array(1) {
  [0]=>
  string(11) "getSomeWhat"
}
array(1) {
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77339&edit=1


Thread (5 messages)

« previous php.bugs (#218584) next »