php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60821 Initialize interned string buffer to avoid valgrind warnings
Submitted: 2012-01-20 18:49 UTC Modified: 2012-01-23 08:28 UTC
From: uw@php.net Assigned: uw (profile)
Status: Closed Package: APC (PECL)
PHP Version: 5.4SVN-2012-01-20 (SVN) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: uw@php.net
New email:
PHP Version: OS:

 

 [2012-01-20 18:49 UTC] uw@php.net
Description:
------------
APC: pecl/svn - trunk (Revision 322504)
PHP: 5_4, svn - PHP 5.4.0RC7-dev
Static build: ./configure  --enable-apc --enable-debug --enable-maintainer-zts

Valgrind barks at APC, like this:

==31961== Conditional jump or move depends on uninitialised value(s)
==31961==    at 0x81B137A: apc_new_interned_string (apc_string.c:82)
==31961==    by 0x81A02D4: apc_string_pmemcpy (apc_compile.c:283)
==31961==    by 0x81A054B: my_copy_zval (apc_compile.c:338)
==31961==    by 0x819FFC5: my_copy_zval_ptr (apc_compile.c:219)
==31961==    by 0x81A1A51: my_copy_hashtable_ex (apc_compile.c:925)
==31961==    by 0x81A05D4: my_copy_zval (apc_compile.c:349)
==31961==    by 0x81A1C52: apc_copy_zval (apc_compile.c:990)
==31961==    by 0x819E6A1: apc_cache_store_zval (apc_cache.c:1114)
==31961==    by 0x819E8A1: apc_cache_make_user_entry (apc_cache.c:1158)
==31961==    by 0x8197464: _apc_store (php_apc.c:610)
==31961==    by 0x81977AC: apc_store_helper (php_apc.c:669)
==31961==    by 0x8197876: zif_apc_add (php_apc.c:689)
==31961== 
==31961== Conditional jump or move depends on uninitialised value(s)
==31961==    at 0x81B1444: apc_new_interned_string (apc_string.c:109)
==31961==    by 0x81A02D4: apc_string_pmemcpy (apc_compile.c:283)
==31961==    by 0x81A054B: my_copy_zval (apc_compile.c:338)
==31961==    by 0x819FFC5: my_copy_zval_ptr (apc_compile.c:219)
==31961==    by 0x81A1A51: my_copy_hashtable_ex (apc_compile.c:925)
==31961==    by 0x81A05D4: my_copy_zval (apc_compile.c:349)
==31961==    by 0x81A1C52: apc_copy_zval (apc_compile.c:990)
==31961==    by 0x819E6A1: apc_cache_store_zval (apc_cache.c:1114)
==31961==    by 0x819E8A1: apc_cache_make_user_entry (apc_cache.c:1158)
==31961==    by 0x8197464: _apc_store (php_apc.c:610)
==31961==    by 0x81977AC: apc_store_helper (php_apc.c:669)
==31961==    by 0x8197876: zif_apc_add (php_apc.c:689)


This is because APC does not initialize its interned_string buffer in  apc_interned_strings_init() .Please, consider initializing the buffer to get rid of the warnings - may not be the worst idea for a string buffer. 

nixnutz@linux-0v4u:~/php-src/branches/PHP_5_4/ext/apc> svn diff
Index: apc_string.c
===================================================================
--- apc_string.c        (Revision 322504)
+++ apc_string.c        (Arbeitskopie)
@@ -198,6 +198,7 @@
     int count = APCG(shm_strings_buffer) / (sizeof(Bucket) + sizeof(Bucket*) * 2);
 
     apc_interned_strings_data = (apc_interned_strings_data_t*) apc_sma_malloc(APCG(shm_strings_buffer) TSRMLS_CC);
+    memset((char *)apc_interned_strings_data, 0, APCG(shm_strings_buffer));
 
     CREATE_LOCK(APCSG(lock));
 





Test script:
---------------
valgrind sapi/cli/php -d apc.enable_cli=1 -r '$tmp = array("foo" => "bar"); apc_add("tmp", $tmp); var_dump(apc_fetch("tmp")); '


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-21 04:55 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2012-01-21 04:55 UTC] rasmus@php.net
Looks right. You have commit karma for all of pecl. Just go ahead commit the fix.
 [2012-01-23 08:17 UTC] uw@php.net
Automatic comment from SVN on behalf of uw
Revision: http://svn.php.net/viewvc/?view=revision&revision=322602
Log: Fix for bug #60821. Initialize buffer to avoid valgrind warnings.
 [2012-01-23 08:28 UTC] uw@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Done, http://news.php.net/php.pecl.cvs/17487 .
 [2012-01-23 08:28 UTC] uw@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: uw
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 12:01:28 2025 UTC