php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58668 Weight of 0 causes SegFault on memcache_add_server
Submitted: 2009-05-11 17:31 UTC Modified: 2010-03-24 09:50 UTC
From: mhackett at bbook dot com Assigned: hradtke (profile)
Status: Closed Package: memcache (PECL)
PHP Version: 5.2.9 OS: RHEL 5.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mhackett at bbook dot com
New email:
PHP Version: OS:

 

 [2009-05-11 17:31 UTC] mhackett at bbook dot com
Description:
------------
memcache_add_server currently only validates that the weight passed from the script is an integer greater than 0. However, if 0 is passed, the function will happily "add" a server while allocating 0 bytes of memory to store it. On subsequent calls to Memcache::get() or ::set(), this causes a segfeault when mmc_open() attempts to access the memcache struct at that address, which of course does not exist.

Below code reproduces for the standard hash strategy, but the same happens with consistent.

Most straightforward solution would seem to be just to change the weight check from "weight < 0" to "weight < 1". It also seems like some more strict constraints on this value (ie, a reasonable max) would be useful.

Reproduce code:
---------------
<?php
ini_set('memcache.hash_strategy', 'standard');
$mmc = new Memcache;
$mmc->addServer('server.local', 22311, true, 0);
$mmc->set('TEST_KEY', 'test_value');
?>


Expected result:
----------------
Memcache::addServer throws an error on attempting to assign a weight of 0, or at least a warning (and then defaults to 1).

Actual result:
--------------
Segmentation fault on the set() call. Backtrace:
#0  0x00002b48bfedc389 in mmc_open (mmc=0x676188e5, force_connect=0, 
    error_string=0x0, errnum=0x0) at /mnt/ebs/memcache-2.2.5/memcache.c:1014
#1  0x00002b48bfee2309 in mmc_standard_find_server (s=0x1e170f30, 
    key=0x7fffefbe57d0 "TEST_KEY", key_len=8)
    at /mnt/ebs/memcache-2.2.5/memcache_standard_hash.c:89
#2  0x00002b48bfedbb00 in mmc_pool_store (pool=0x1e172558, 
    command=0x2b48bfee44ac "set", command_len=3, 
    key=0x7fffefbe57d0 "TEST_KEY", key_len=8, flags=0, expire=0, 
    value=0x1e172890 "test_value", value_len=10)
    at /mnt/ebs/memcache-2.2.5/memcache.c:809
#3  0x00002b48bfedf619 in php_mmc_store (ht=2, return_value=0x1e172258, 
    return_value_ptr=0x0, this_ptr=0x1e170268, return_value_used=0, 
    command=0x2b48bfee44ac "set", command_len=3)
    at /mnt/ebs/memcache-2.2.5/memcache.c:1820
#4  0x00002b48bfee0d2b in zif_memcache_set (ht=2, return_value=0x1e172258, 
    return_value_ptr=0x0, this_ptr=0x1e170268, return_value_used=0)
    at /mnt/ebs/memcache-2.2.5/memcache.c:2318
#5  0x00000000007aa11b in zend_do_fcall_common_helper_SPEC (
    execute_data=0x7fffefbe5c30)
    at /mnt/ebs/php-5.2.9/Zend/zend_vm_execute.h:200
#6  0x00000000007aafed in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER (
    execute_data=0x7fffefbe5c30)
    at /mnt/ebs/php-5.2.9/Zend/zend_vm_execute.h:322
#7  0x00000000007a9b68 in execute (op_array=0x1e170fa8)
    at /mnt/ebs/php-5.2.9/Zend/zend_vm_execute.h:92
#8  0x000000000077f341 in zend_execute_scripts (type=8, retval=0x0, 
    file_count=3) at /mnt/ebs/php-5.2.9/Zend/zend.c:1134
#9  0x000000000071e5fc in php_execute_script (primary_file=0x7fffefbe82a0)
    at /mnt/ebs/php-5.2.9/main/main.c:2023
#10 0x000000000080ae8d in main (argc=2, argv=0x7fffefbe84f8)
    at /mnt/ebs/php-5.2.9/sapi/cli/php_cli.c:1133


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-24 09:50 UTC] hradtke@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 13:01:30 2024 UTC