Skip to content

Commit 5a177d4

Browse files
committed
Merge in changes from master branch of upstream php-memcached (3.0.3 release)
2 parents b1300bf + 466485a commit 5a177d4

21 files changed

+251
-38
lines changed

ChangeLog

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
memcached extension changelog
22

3+
Version 3.0.3 (2017-02-19)
4+
--------------------------
5+
6+
* Fix crash when checking session data with older versions of libmemcached (#328)
7+
* Fix crash due to zend_mm_corrupted when fetching session data (#327)
8+
9+
Version 3.0.2 (2017-02-12)
10+
--------------------------
11+
12+
* Update warning for touch command in binary protocol mode with libmemcached < 1.0.18 (#322)
13+
* Add tests for 64-bit increment/decrement/incrementByKey/decrementByKey (#321)
14+
* Fix tests for 32-bit increment/decrement/incrementByKey/decrementByKey (#319)
15+
316
Version 3.0.1 (2017-02-07)
4-
-------------
17+
--------------------------
518

619
* Add API entries for flushBuffers() and getAllKeys() (#316)
720
* Ignore specific errors from memcached_dump for getAllKeys() with newer memcached servers (#315)

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ php-memcached 2.x:
9999
* Optionally supports igbinary 1.0 or higher.
100100
* Optionally supports msgpack 0.5 or higher.
101101

102-
[libmemcached](http://libmemcached.org/libMemcached.html) version 1.0.16 or
102+
[libmemcached](http://libmemcached.org/libMemcached.html) version 1.0.18 or
103103
higher is recommended for best performance and compatibility with memcached
104104
servers.
105105

package.xml

+58-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
2121
<email>[email protected]</email>
2222
<active>yes</active>
2323
</lead>
24-
<date>2017-02-07</date>
24+
<lead>
25+
<name>Aaron Stone</name>
26+
<user>sodabrew</user>
27+
<email>[email protected]</email>
28+
<active>yes</active>
29+
</lead>
30+
<date>2017-02-19</date>
2531
<version>
26-
<release>3.0.1</release>
32+
<release>3.0.3</release>
2733
<api>3.0.0</api>
2834
</version>
2935
<stability>
@@ -37,11 +43,8 @@ and the oldest actively tested version is 1.0.2. It is highly recommended to use
3743
libmemcached.
3844

3945
Fixes
40-
* Add API entries for flushBuffers() and getAllKeys() (#316)
41-
* Ignore specific errors from memcached_dump for getAllKeys() with newer memcached servers (#315)
42-
* Fix compiling with memcached binary protocol enabled (#312)
43-
* Restore php_libmemcached_compat with workaround for missing memcached_exists (#314)
44-
* Travis CI purge old versions of memcached and libmemcached (#309)
46+
* Fix crash when checking session data with older versions of libmemcached (#328)
47+
* Fix crash due to zend_mm_corrupted when fetching session data (#327)
4548
</notes>
4649
<contents>
4750
<dir name="/">
@@ -68,6 +71,7 @@ Fixes
6871
<file role='src' name='fastlz/fastlz.c'/>
6972
<file role='src' name='fastlz/fastlz.h'/>
7073
<dir name="tests">
74+
<file role='test' name='skipif.inc'/>
7175
<file role='test' name='001.phpt'/>
7276
<file role='test' name='version.phpt'/>
7377
<file role='test' name='bug_16084.phpt'/>
@@ -112,6 +116,7 @@ Fixes
112116
<file role='test' name='session_basic.phpt'/>
113117
<file role='test' name='session_basic2.phpt'/>
114118
<file role='test' name='session_basic3.phpt'/>
119+
<file role='test' name='session_persistent.phpt'/>
115120
<file role='test' name='set_large.phpt'/>
116121
<file role='test' name='setoptions.phpt'/>
117122
<file role='test' name='touch_binary.phpt'/>
@@ -137,6 +142,7 @@ Fixes
137142
<file role='test' name='setmulti.phpt'/>
138143
<file role='test' name='cachecallback.phpt'/>
139144
<file role='test' name='incrdecr.phpt'/>
145+
<file role='test' name='incrdecr_64.phpt'/>
140146
<file role='test' name='incrdecr_initial.phpt'/>
141147
<file role='test' name='incrdecr_invalid_key.phpt'/>
142148
<file role='test' name='incrdecr_bykey.phpt'/>
@@ -149,6 +155,7 @@ Fixes
149155
<file role='test' name='gh_155.phpt'/>
150156
<file role='test' name='get_flags.phpt'/>
151157
<file role='test' name='session_lock.phpt'/>
158+
<file role='test' name='session_lazy_warning.phpt'/>
152159
<file role='test' name='session_regenerate.phpt'/>
153160
<file role='test' name='stats.phpt'/>
154161
<file role='test' name='default_behavior.phpt'/>
@@ -182,6 +189,50 @@ Fixes
182189
<configureoption name="with-libmemcached-dir" default="no" prompt="libmemcached directory"/>
183190
</extsrcrelease>
184191
<changelog>
192+
<release>
193+
<stability>
194+
<release>stable</release>
195+
<api>stable</api>
196+
</stability>
197+
<version>
198+
<release>3.0.2</release>
199+
<api>3.0.0</api>
200+
</version>
201+
<date>2016-02-12</date>
202+
<notes>
203+
PHP7 release of memcached extension. Note that support for libmemcached 0.x series has been discontinued
204+
and the oldest actively tested version is 1.0.2. It is highly recommended to use version 1.0.18 of
205+
libmemcached.
206+
207+
Fixes
208+
* Update warning for touch command in binary protocol mode with libmemcached below 1.0.18 (#322)
209+
* Add tests for 64-bit increment/decrement/incrementByKey/decrementByKey (#321)
210+
* Fix tests for 32-bit increment/decrement/incrementByKey/decrementByKey (#319)
211+
</notes>
212+
</release>
213+
<release>
214+
<stability>
215+
<release>stable</release>
216+
<api>stable</api>
217+
</stability>
218+
<version>
219+
<release>3.0.1</release>
220+
<api>3.0.0</api>
221+
</version>
222+
<date>2016-02-07</date>
223+
<notes>
224+
PHP7 release of memcached extension. Note that support for libmemcached 0.x series has been discontinued
225+
and the oldest actively tested version is 1.0.2. It is highly recommended to use version 1.0.18 of
226+
libmemcached.
227+
228+
Fixes
229+
* Add API entries for flushBuffers() and getAllKeys() (#316)
230+
* Ignore specific errors from memcached_dump for getAllKeys() with newer memcached servers (#315)
231+
* Fix compiling with memcached binary protocol enabled (#312)
232+
* Restore php_libmemcached_compat with workaround for missing memcached_exists (#314)
233+
* Travis CI purge old versions of memcached and libmemcached (#309)
234+
</notes>
235+
</release>
185236
<release>
186237
<stability>
187238
<release>stable</release>

php_libmemcached_compat.c

+26-4
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,42 @@
1818
#include "php_memcached_private.h"
1919
#include "php_libmemcached_compat.h"
2020

21-
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key)
21+
memcached_return php_memcached_exist(memcached_st *memc, zend_string *key)
2222
{
2323
#ifdef HAVE_MEMCACHED_EXIST
24-
return memcached_exist (memc, key->val, key->len);
24+
return memcached_exist(memc, key->val, key->len);
2525
#else
2626
memcached_return rc = MEMCACHED_SUCCESS;
2727
uint32_t flags = 0;
2828
size_t value_length = 0;
2929
char *value = NULL;
3030

31-
value = memcached_get (memc, key->val, key->len, &value_length, &flags, &rc);
31+
value = memcached_get(memc, key->val, key->len, &value_length, &flags, &rc);
3232
if (value) {
33-
free (value);
33+
zend_bool *is_persistent = memcached_get_user_data(memc);
34+
pefree(value, *is_persistent);
3435
}
3536
return rc;
3637
#endif
3738
}
39+
40+
memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration)
41+
{
42+
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018
43+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) {
44+
php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached");
45+
}
46+
#endif
47+
return memcached_touch(memc, key, key_len, expiration);
48+
}
49+
50+
memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration)
51+
{
52+
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018
53+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) {
54+
php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached");
55+
}
56+
#endif
57+
return memcached_touch_by_key(memc, server_key, server_key_len, key, key_len, expiration);
58+
}
59+

php_libmemcached_compat.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);
2424

25+
memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration);
26+
memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration);
27+
2528
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
2629
typedef const memcached_instance_st * php_memcached_instance_st;
2730
#else

php_memcached.c

+2-11
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ zend_bool s_memc_write_zval (php_memc_object_t *intern, php_memc_write_op op, ze
10811081
break;
10821082

10831083
case MEMC_OP_TOUCH:
1084-
status = memcached_touch_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), expiration);
1084+
status = php_memcached_touch_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), expiration);
10851085
break;
10861086

10871087
case MEMC_OP_ADD:
@@ -1113,7 +1113,7 @@ zend_bool s_memc_write_zval (php_memc_object_t *intern, php_memc_write_op op, ze
11131113
break;
11141114

11151115
case MEMC_OP_TOUCH:
1116-
status = memcached_touch(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), expiration);
1116+
status = php_memcached_touch(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), expiration);
11171117
break;
11181118

11191119
case MEMC_OP_ADD:
@@ -1959,15 +1959,6 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
19591959
}
19601960
}
19611961

1962-
1963-
if (op == MEMC_OP_TOUCH) {
1964-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000016
1965-
if (memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) {
1966-
php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.16");
1967-
}
1968-
#endif
1969-
}
1970-
19711962
if (!s_memc_write_zval (intern, op, server_key, key, value, expiration)) {
19721963
RETURN_FALSE;
19731964
}

php_memcached.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# include "config.h"
2828
#endif
2929

30-
#define PHP_MEMCACHED_VERSION "3.0.1"
30+
#define PHP_MEMCACHED_VERSION "3.0.3"
3131

3232
#if defined(PHP_WIN32) && defined(MEMCACHED_EXPORTS)
3333
#define PHP_MEMCACHED_API __declspec(dllexport)

php_memcached_session.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ PS_OPEN_FUNC(memcached)
351351
else {
352352
efree(plist_key);
353353
PS_SET_MOD_DATA(memc);
354+
memcached_server_list_free(servers);
354355
return SUCCESS;
355356
}
356357
}
@@ -435,8 +436,9 @@ PS_READ_FUNC(memcached)
435436
payload = memcached_get(memc, key->val, key->len, &payload_len, &flags, &status);
436437

437438
if (status == MEMCACHED_SUCCESS) {
439+
zend_bool *is_persistent = memcached_get_user_data(memc);
438440
*val = zend_string_init(payload, payload_len, 0);
439-
efree(payload);
441+
pefree(payload, *is_persistent);
440442
return SUCCESS;
441443
} else if (status == MEMCACHED_NOTFOUND) {
442444
*val = ZSTR_EMPTY_ALLOC();
@@ -542,7 +544,7 @@ PS_UPDATE_TIMESTAMP_FUNC(memcached)
542544
memcached_st *memc = PS_GET_MOD_DATA();
543545
time_t expiration = s_session_expiration(maxlifetime);
544546

545-
if (memcached_touch(memc, key->val, key->len, expiration) == MEMCACHED_FAILURE) {
547+
if (php_memcached_touch(memc, key->val, key->len, expiration) == MEMCACHED_FAILURE) {
546548
return FAILURE;
547549
}
548550
return SUCCESS;

tests/gh_155.phpt

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ Test for bug 155
44
<?php
55
$min_version = "1.4.8";
66
include dirname(__FILE__) . "/skipif.inc";
7-
if (Memcached::LIBMEMCACHED_VERSION_HEX < 0x01000016) die ('skip too old libmemcached');
7+
// The touch command in binary mode will work in libmemcached 1.0.16, but runs out the timeout clock
8+
// See https://github.com/php-memcached-dev/php-memcached/issues/310 for further explanation
9+
// The problem is fixed fully in libmemcached 1.0.18, so we'll focus tests on that version
10+
if (Memcached::LIBMEMCACHED_VERSION_HEX < 0x01000018) die ('skip too old libmemcached');
811
?>
912
--FILE--
1013
<?php
1114
include dirname (__FILE__) . '/config.inc';
1215

1316
$m = new Memcached ();
1417

15-
$m->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
18+
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
1619
$m->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT);
1720

1821
$key = 'bug_155_' . uniqid();

tests/gh_90.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $memcached = memc_get_instance (array (
1212
// Create a key for use as a lock. If this key already exists, wait till it doesn't exist.
1313
{
1414
$key = 'LockKey';
15-
$lockToken = mt_rand(0, pow(2, 32)); //Random value betwen 0 and 2^32 for ownership verification
15+
$lockToken = mt_rand(0, mt_getrandmax()); //Random value for ownership verification
1616

1717
while (true)
1818
{
@@ -88,4 +88,4 @@ array(10) {
8888
int(1)
8989
["9_%s"]=>
9090
int(1)
91-
}
91+
}

tests/incrdecr.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ echo $php_errormsg, "\n";
4242
var_dump($m->get('foo'));
4343

4444
echo "Enormous offset\n";
45-
$m->increment('foo', 4294967296);
45+
$m->increment('foo', 0x7f000000);
4646
var_dump($m->get('foo'));
4747

48-
$m->decrement('foo', 4294967296);
48+
$m->decrement('foo', 0x7f000000);
4949
var_dump($m->get('foo'));
5050

5151
--EXPECT--
@@ -68,5 +68,5 @@ int(1)
6868
Memcached::decrement(): offset cannot be a negative value
6969
int(1)
7070
Enormous offset
71-
int(4294967297)
71+
int(2130706433)
7272
int(1)

tests/incrdecr_64.phpt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
64-bit Memcached::increment() decrement() incrementByKey() decrementByKey()
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
if (PHP_INT_SIZE < 8) die("skip valid for 64-bit PHP only");
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
$m = memc_get_instance ();
12+
13+
echo "Normal\n";
14+
$m->set('foo', 1);
15+
var_dump($m->get('foo'));
16+
17+
echo "Enormous offset 64-bit\n";
18+
$m->increment('foo', 0x100000000);
19+
var_dump($m->get('foo'));
20+
21+
$m->decrement('foo', 0x100000000);
22+
var_dump($m->get('foo'));
23+
24+
echo "Enormous offset 64-bit by key\n";
25+
$m->incrementByKey('foo', 'foo', 0x100000000);
26+
var_dump($m->get('foo'));
27+
28+
$m->decrementByKey('foo', 'foo', 0x100000000);
29+
var_dump($m->get('foo'));
30+
31+
--EXPECT--
32+
Normal
33+
int(1)
34+
Enormous offset 64-bit
35+
int(4294967297)
36+
int(1)
37+
Enormous offset 64-bit by key
38+
int(4294967297)
39+
int(1)

tests/incrdecr_bykey.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ echo $php_errormsg, "\n";
3939
var_dump($m->get('foo'));
4040

4141
echo "Enormous offset\n";
42-
$m->incrementByKey('foo', 'foo', 4294967296);
42+
$m->incrementByKey('foo', 'foo', 0x7f000000);
4343
var_dump($m->get('foo'));
4444

45-
$m->decrementByKey('foo', 'foo', 4294967296);
45+
$m->decrementByKey('foo', 'foo', 0x7f000000);
4646
var_dump($m->get('foo'));
4747

4848
--EXPECT--
@@ -62,5 +62,5 @@ int(1)
6262
Memcached::decrementByKey(): offset cannot be a negative value
6363
int(1)
6464
Enormous offset
65-
int(4294967297)
65+
int(2130706433)
6666
int(1)

tests/session_basic.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if (!Memcached::HAVE_SESSION) print "skip";
77
?>
88
--INI--
99
session.save_handler = memcached
10+
memcached.sess_binary_protocol = Off
1011
--FILE--
1112
<?php
1213
include dirname (__FILE__) . '/config.inc';

0 commit comments

Comments
 (0)