Skip to content

Commit

Permalink
Fix #78189: file cache strips last character of uname hash
Browse files Browse the repository at this point in the history
We must not forget to increase `len` by one to cater to the directory
separator.
  • Loading branch information
cmb69 committed Jun 20, 2019
1 parent d8202bf commit fcd6f2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -9,6 +9,9 @@ PHP NEWS
- Date:
. Fixed #69044 (discrepency between time and microtime). (krakjoe)

- OPcache:
. Fixed #78189 (file cache strips last character of uname hash). (cmb)

27 Jun 2019, PHP 7.2.20

- Core:
Expand Down
22 changes: 22 additions & 0 deletions ext/opcache/tests/bug78189.phpt
@@ -0,0 +1,22 @@
--TEST--
Bug #78189 (file cache strips last character of uname hash)
--SKIPIF--
<?php
if (!extension_loaded('Zend OPcache')) die('skip opcache extension not available');
if (substr(PHP_OS, 0, 3) !== 'WIN') die('skip this test is for Windows platforms only');
?>
--INI--
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.file_cache={TMP}
opcache.file_cache_only=1
--FILE--
<?php
$tmpdir = sys_get_temp_dir();
$pattern = $tmpdir . '/*/*/' . str_replace(':', '', __DIR__) . '/bug78189.php.bin';
foreach (glob($pattern) as $filename) {
var_dump(preg_match('~/[0-9a-f]{32}/~', substr($filename, strlen($tmpdir), 34)));
}
?>
--EXPECT--
int(1)
2 changes: 1 addition & 1 deletion ext/opcache/zend_file_cache.c
Expand Up @@ -775,7 +775,7 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
memcpy(filename, ZCG(accel_directives).file_cache, len);
filename[len] = '\\';
memcpy(filename + 1 + len, md5uname, 32);
len += 32;
len += 1 + 32;
filename[len] = '\\';

memcpy(filename + len + 1, ZCG(system_id), 32);
Expand Down

0 comments on commit fcd6f2d

Please sign in to comment.