Skip to content

set() fails if 3rd param is null #407

@nfrm

Description

@nfrm

This bug seems to have been introduced with 2.2.4

<?php

    $redis = new redis;
    $redis->connect('127.0.0.1');

    $redis->del("test");

    echo $redis->exists("test") ? 'EXISTS' : 'DOES NOT EXIST';
    echo "\n";

    $redis->set("test", "hello", null);

    echo $redis->exists("test") ? 'EXISTS' : 'DOES NOT EXIST';
    echo "\n";

    $redis->set("test", "hello");

    echo $redis->exists("test") ? 'EXISTS' : 'DOES NOT EXIST';
    echo "\n";

Result:

DOES NOT EXIST
DOES NOT EXIST
EXISTS

When testing with 2.2.3, the results are:

DOES NOT EXIST
EXISTS
EXISTS

I'm guessing it's because of this:

https://github.com/nicolasff/phpredis/blob/2.2.4/redis.c#L839-L841

I'm not overly adept with PHP's internal library, but I would assume a zval (even with it's value being null) will evaluate as true in C, causing if(z_opts) to evaluate as true.

This should work as a fix:

if(z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY && Z_TYPE_P(z_opts) != IS_NULL) {
    RETURN_FALSE;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions