Skip to content

Commit

Permalink
Merge pull request #390 from reliforp/fix-filename-detection
Browse files Browse the repository at this point in the history
Fix the bug that filename or lineno of internal function call are set incorrectly
  • Loading branch information
sj-i authored Dec 18, 2023
2 parents 6e80663 + b1c746a commit 8322794
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/Lib/PhpInternals/Types/Zend/ZendFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ public function getClassName(Dereferencer $dereferencer): ?string
public function getFileName(Dereferencer $dereferencer): ?string
{
if (!isset($this->resolved_file_name_cache)) {
if (!$this->isUserFunction()) {
if ($this->isInternalFunction()) {
$this->resolved_file_name_cache = '<internal>';
} else {
$this->resolved_file_name_cache = $this->op_array->getFileName($dereferencer);
}
$this->resolved_file_name_cache = $this->op_array->getFileName($dereferencer);
}
return $this->resolved_file_name_cache;
}
Expand Down
53 changes: 41 additions & 12 deletions tests/Lib/PhpProcessReader/CallTraceReader/CallTraceReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,25 @@ public function testReadCallTrace()
new ZendTypeReaderCreator(),
new OpcodeFactory()
);
$tmp_file = tempnam(sys_get_temp_dir(), 'reli-prof-test');
file_put_contents(
$tmp_file,
<<<CODE
<?php
class A {
public function wait() {
fgets(STDIN);
}
}
\$object = new A;
fputs(STDOUT, "a\n");
\$object->wait();
CODE
);
$this->child = proc_open(
[
PHP_BINARY,
'-r',
<<<CODE
class A {
public function wait() {
fgets(STDIN);
}
}
\$object = new A;
fputs(STDOUT, "a\n");
\$object->wait();
CODE
$tmp_file,
],
[
['pipe', 'r'],
Expand Down Expand Up @@ -113,7 +118,7 @@ public function wait() {

$call_trace = $executor_globals_reader->readCallTrace(
$child_status['pid'],
ZendTypeReader::V74,
ZendTypeReader::V81,
$executor_globals_address,
$sapi_globals_address,
PHP_INT_MAX,
Expand All @@ -124,13 +129,37 @@ public function wait() {
'fgets',
$call_trace->call_frames[0]->getFullyQualifiedFunctionName()
);
$this->assertSame(
'<internal>',
$call_trace->call_frames[0]->file_name
);
$this->assertSame(
null,
$call_trace->call_frames[0]->opline
);
$this->assertSame(
'A::wait',
$call_trace->call_frames[1]->getFullyQualifiedFunctionName()
);
$this->assertSame(
$tmp_file,
$call_trace->call_frames[1]->file_name
);
$this->assertSame(
4,
$call_trace->call_frames[1]->opline->lineno
);
$this->assertSame(
'<main>',
$call_trace->call_frames[2]->getFullyQualifiedFunctionName()
);
$this->assertSame(
$tmp_file,
$call_trace->call_frames[2]->file_name
);
$this->assertSame(
10,
$call_trace->call_frames[2]->opline->lineno
);
}
}

0 comments on commit 8322794

Please sign in to comment.