php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61742 preload_path does not work due to incorrect string length
Submitted: 2012-04-16 07:02 UTC Modified: 2012-08-13 13:11 UTC
From: bas5winkel at gmail dot com Assigned: ab (profile)
Status: Closed Package: APC (PECL)
PHP Version: 5.3Git-2012-04-16 (snap) OS: Debian
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: bas5winkel at gmail dot com
New email:
PHP Version: OS:

 

 [2012-04-16 07:02 UTC] bas5winkel at gmail dot com
Description:
------------
Inside 'main_apc.c' in the method called 'static int apc_load_data(const char *data_file TSRMLS_DC)', the length of the key of the value that needs to be stored is determined with the following line :
key_len = strlen(key);
If I am correct this is only the length of the string itself without the null-terminator
However, "_apc_store" seems to want the length of the key string including the terminator. 
If I change the line above to :
key_len = strlen(key)+1;
then it works as expected.

You can also notice that 1 character is missing when looking at the user cache entries apc.php. But if you try to use that as a key then APC will not return the contents so that didn't work as a workaround.

Test script:
---------------
1. Create a small textfile called 'abc.data' with the following string:
     s:2:"123"
  Make sure it has a null terminator at the end of the string.

2. set the apc.preload_path= setting to a certain path.
3. move the text file to that directory
4. reload Apache
5. run apc.php and check the user entries.
6. note that the name of the entry will be 'ab' and that nor 'ab' or 'abc' will return the contents.


Expected result:
----------------
a serialized file with the filename 'abc.data' will be loaded into the apc user entries and with the key 'abc' one can retrieve the data.


Actual result:
--------------
a serialized file with the filename 'abc.data' will be loaded but the name of the key will be 'ab' and it's contents cannot be retrieved

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-13 13:04 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&revision=327102
Log: Fix bug #61742 preload_path does not work due to incorrect string length

- producing key taking \0 into account for length, this is also correct
  for other functions working with user cache (like apc_fetch, apc_exists, etc.)
- for PHP 5.4 additionally - interned strings must be initialized before
  user data preloading
 [2012-08-13 13:11 UTC] ab@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2012-08-13 13:11 UTC] ab@php.net
Shouldn't it be s:3:"123" instead of s:2:"123"? Anyway, fixed in svn now, please 
test also with php 5.4 .
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 01:01:33 2024 UTC