Skip to content

Commit

Permalink
Verify SET options are strings before testing them as strings. (#1859)
Browse files Browse the repository at this point in the history
Addresses #1835
  • Loading branch information
michael-grunder committed Oct 13, 2020
1 parent 44345f0 commit 514bc37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions redis_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,10 +1370,12 @@ int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
} else if (Z_TYPE_P(v) == IS_STRING) {
expire = atol(Z_STRVAL_P(v));
}
} else if (ZVAL_STRICMP_STATIC(v, "KEEPTTL")) {
keep_ttl = 1;
} else if (ZVAL_IS_NX_XX_ARG(v)) {
set_type = Z_STRVAL_P(v);
} else if (Z_TYPE_P(v) == IS_STRING) {
if (ZVAL_STRICMP_STATIC(v, "KEEPTTL")) {
keep_ttl = 1;
} else if (ZVAL_IS_NX_XX_ARG(v)) {
set_type = Z_STRVAL_P(v);
}
}
} ZEND_HASH_FOREACH_END();
} else if (z_opts && Z_TYPE_P(z_opts) != IS_NULL) {
Expand Down
5 changes: 5 additions & 0 deletions tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ public function testExtendedSet() {
$this->assertEquals($this->redis->get('foo'), 'bar');
$this->assertTrue($this->redis->ttl('foo')<0);

/* Make sure we ignore bad/non-string options (regression test for #1835) */
$this->assertTrue($this->redis->set('foo', 'bar', [NULL, 'EX' => 60]));
$this->assertTrue($this->redis->set('foo', 'bar', [NULL, new stdClass(), 'EX' => 60]));
$this->assertFalse(@$this->redis->set('foo', 'bar', [NULL, 'EX' => []]));

if (version_compare($this->version, "6.0.0") < 0)
return;

Expand Down

0 comments on commit 514bc37

Please sign in to comment.