Skip to content

Commit 56d5b97

Browse files
committed
Merge branch 'master' of github.com:php-memcached-dev/php-memcached into testing-flags
2 parents 1010295 + eaa92d4 commit 56d5b97

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

php_memcached.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,18 +3141,29 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_
31413141

31423142
case MEMC_VAL_IS_LONG:
31433143
{
3144+
long lval;
31443145
char conv_buf [128];
3146+
3147+
if (payload_len >= 128) {
3148+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read long value, too big");
3149+
goto my_error;
3150+
}
31453151
memcpy (conv_buf, pl, payload_len);
31463152
conv_buf [payload_len] = '\0';
31473153

3148-
long lval = strtol(conv_buf, NULL, 10);
3154+
lval = strtol(conv_buf, NULL, 10);
31493155
ZVAL_LONG(value, lval);
3150-
break;
31513156
}
3157+
break;
31523158

31533159
case MEMC_VAL_IS_DOUBLE:
31543160
{
31553161
char conv_buf [128];
3162+
3163+
if (payload_len >= 128) {
3164+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read double value, too big");
3165+
goto my_error;
3166+
}
31563167
memcpy (conv_buf, pl, payload_len);
31573168
conv_buf [payload_len] = '\0';
31583169

tests/gh_93.phpt

Lines changed: 45 additions & 0 deletions
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)