laminas / laminas-server

Create Reflection-based RPC servers
https://docs.laminas.dev/laminas-server/
BSD 3-Clause "New" or "Revised" License
25 stars 14 forks source link

Fixed error when receiving null $argv in Reflection::reflectClass/reflectFunction #19

Closed mtorromeo closed 3 years ago

mtorromeo commented 3 years ago
Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Given the loose typehints in ReflectionClass and ReflectionMethod it can happen that they receive null as the $argv parameter, leading to an error.

In practice this happened to me when using laminas-json-server which contains the following code with $argv defaulting to null:

    public function setClass($class, $namespace = '', $argv = null)
    {
        if (2 < func_num_args()) {
            $argv = func_get_args();
            $argv = array_slice($argv, 2);
        }

        $reflection = Reflection::reflectClass($class, $argv, $namespace);

        foreach ($reflection->getMethods() as $method) {
            $definition = $this->_buildSignature($method, $class);
            $this->addMethodServiceMap($definition);
        }

        return $this;
    }

The code from Laminas\Json\Server contains its own bug given that if (2 < func_num_args()) { should more likely be if (3 < func_num_args()) {, but still it seems right to at least protect from such a situation in laminas-server as well.

goksiii commented 3 years ago

hello @mtorromeo,

when do you plan to merge this PR because we have problems with Laminas Server?

mtorromeo commented 3 years ago

@goksiii I'm not a maintainer/developer of the project and I can't merge anything. I want this merged as much as you do.

weierophinney commented 3 years ago

I'll try and review today, @goksiii.