PHP  
 PHP_7_0
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Valgrind Report for sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt ('Getting executable lines from custom wrappers')

Script

1: <?php
2:
3:
/**
4:  * This example demonstrates how phpdbg_get_executable() behaves differently
5:  * when passed the 'files' option vs without, in the face of some mild abuse
6:  * of stream wrappers.
7:  */
8:
9: /**
10:  * First, we define a stream wrapper that simply maps to a real file on disk.
11:  */
12:
final class StreamWrapper
13:
{
14:     public function 
stream_open(
15:         
string $path,
16:         
string $mode,
17:         
int $options 0,
18:         
string &$openedPath null
19:     
) : bool {
20:         if (
$mode[0] !== 'r') {
21:             return 
false;
22:         }
23:
24:         list(
$scheme$path) = explode('://'$path2);
25:
26:         
$stream = \fopen($path$mode);
27:
28:         if (
$stream === false) {
29:             return 
false;
30:         }
31:
32:         
$this->stream $stream;
33:
34:         
/**
35:          * The $openedPath reference variable is assigned, indicating the
36:          * *actual* path that was opened. This affects the behaviour of
37:          * constants like __FILE__.
38:          */
39:         
$openedPath = \realpath($path);
40:
41:         return 
true;
42:     }
43:
44:     public function 
stream_read(int $count) : string { return \fread($this->stream$count); }
45:     public function 
stream_close() : bool { return \fclose($this->stream); }
46:     public function 
stream_eof() : bool { return \feof($this->stream); }
47:     public function 
stream_stat() { return \fstat($this->stream); }
48:
49:     private 
$stream false;
50: }
51:
52:
stream_wrapper_register('wrapper'StreamWrapper::class);
53:
54:
/**
55:  * Next, we include a PHP file that contains executable lines, via the stream
56:  * wrapper.
57:  */
58:
$filename __DIR__ '/phpdbg_get_executable_stream_wrapper.inc';
59: require 
'wrapper://' $filename;
60:
61:
/**
62:  * If we call phpdbg_get_executable() and pass no options, the realpath of the
63:  * included file is present in the array, but indicates no executable lines.
64:  */
65:
$x phpdbg_get_executable();
66:
67:
// We expect [5 => 0], but got an empty array ...
68:
var_dump($x[$filename]);
69:
70:
?>
71:

Report

==6503== Invalid read of size 4
==6503==    at 0xA31D562: kpufhndl0 (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA323952: kpufhndl (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA1ED5C4: OCIHandleFree (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA661F8: zm_shutdown_pdo_oci (pdo_oci.c:142)
==6503==    by 0xFD87BE: module_destructor (zend_API.c:2505)
==6503==    by 0xFC2D0B: module_destructor_zval (zend.c:620)
==6503==    by 0xFFB1D9: _zend_hash_del_el_ex (zend_hash.c:1025)
==6503==    by 0xFFB1D9: _zend_hash_del_el (zend_hash.c:1049)
==6503==    by 0xFFB1D9: zend_hash_graceful_reverse_destroy (zend_hash.c:1505)
==6503==    by 0xFD40B4: zend_destroy_modules (zend_API.c:1982)
==6503==    by 0xFC3776: zend_shutdown (zend.c:856)
==6503==    by 0xEC2C02: php_module_shutdown (main.c:2386)
==6503==    by 0x11CF106: main (phpdbg.c:2145)
==6503==  Address 0x14f4b110 is 0 bytes inside a block of size 43,632 free'd
==6503==    at 0x4C28BD4: free (vg_replace_malloc.c:529)
==6503==    by 0xA613CDE: ssMemFree (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA6D9ED9: sktsfFree (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xB069F6B: kpummefree (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA3236E6: kpufhndl0 (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA323952: kpufhndl (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA1ED5C4: OCIHandleFree (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA661F8: zm_shutdown_pdo_oci (pdo_oci.c:142)
==6503==    by 0xFD87BE: module_destructor (zend_API.c:2505)
==6503==    by 0xFC2D0B: module_destructor_zval (zend.c:620)
==6503==    by 0xFFB1D9: _zend_hash_del_el_ex (zend_hash.c:1025)
==6503==    by 0xFFB1D9: _zend_hash_del_el (zend_hash.c:1049)
==6503==    by 0xFFB1D9: zend_hash_graceful_reverse_destroy (zend_hash.c:1505)
==6503==    by 0xFD40B4: zend_destroy_modules (zend_API.c:1982)
==6503==  Block was alloc'd at
==6503==    at 0x4C291FA: malloc (vg_replace_malloc.c:298)
==6503==    by 0xA613CEC: ssMemMalloc (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA6D9EEB: sktsfMalloc (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xB069EFD: kpummealloc (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA32D030: kpuinit0 (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA32B2FC: kpuenvcr (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA1ED4E9: OCIEnvCreate (in /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1)
==6503==    by 0xA6616C: zm_activate_pdo_oci (pdo_oci.c:120)
==6503==    by 0xFD897B: zend_activate_modules (zend_API.c:2543)
==6503==    by 0xEC06B1: php_request_startup (main.c:1652)
==6503==    by 0x11CD84A: main (phpdbg.c:1793)
==6503== 

 

Generated at Wed, 08 Nov 2017 19:36:35 +0000 (10 days ago)

Copyright © 2005-2017 The PHP Group
All rights reserved.