Skip to content

Commit 731c693

Browse files
author
Mikko Koppanen
committed
Merge pull request #94 from poison/fix_gh93
Fixes issue #93
2 parents 3c6e305 + 994e334 commit 731c693

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

php_memcached.c

+10
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,11 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_
30533053

30543054
case MEMC_VAL_IS_LONG:
30553055
{
3056+
if (payload_len >= 128) {
3057+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read long value, too big");
3058+
goto my_error;
3059+
}
3060+
30563061
char conv_buf [128];
30573062
memcpy (conv_buf, pl, payload_len);
30583063
conv_buf [payload_len] = '\0';
@@ -3064,6 +3069,11 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_
30643069

30653070
case MEMC_VAL_IS_DOUBLE:
30663071
{
3072+
if (payload_len >= 128) {
3073+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read double value, too big");
3074+
goto my_error;
3075+
}
3076+
30673077
char conv_buf [128];
30683078
memcpy (conv_buf, pl, payload_len);
30693079
conv_buf [payload_len] = '\0';

tests/gh_93.phpt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Test for Github issue #93 (double and long overflow)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
$m->setOption(Memcached::OPT_COMPRESSION, false);
10+
11+
function testOverflow($m, $value) {
12+
$m->delete('overflow');
13+
if (true !== $m->set('overflow', $value)) {
14+
echo "Error storing 'overflow' variable\n";
15+
return false;
16+
}
17+
18+
if (true !== $m->prepend('overflow', str_repeat('0', 128))) {
19+
echo "Error prepending key\n";
20+
return false;
21+
}
22+
23+
$v = @$m->get('overflow');
24+
if ($v !== $value) {
25+
// At least it doesn't segfault, so we're happy for now
26+
// echo "Error receiving 'overflow' variable\n";
27+
// return false;
28+
return true;
29+
}
30+
31+
return true;
32+
}
33+
34+
if (!testOverflow($m, 10)) {
35+
return;
36+
}
37+
38+
if (!testOverflow($m, 9.09)) {
39+
return;
40+
}
41+
42+
echo "OK\n";
43+
?>
44+
--EXPECT--
45+
OK

0 commit comments

Comments
 (0)