Avoid infinite loops when profiler data is malformed

This commit is contained in:
Javier Eguiluz 2017-08-03 22:11:44 +02:00
parent e1ffb3341d
commit e5ef9fb74a
1 changed files with 11 additions and 3 deletions

View File

@ -144,11 +144,19 @@ class FileProfilerStorage implements ProfilerStorageInterface
}
}
$profileToken = $profile->getToken();
// when there are errors in sub-requests, the parent and/or children tokens
// may equal the profile token, resulting in infinite loops
$parentToken = $profile->getParentToken() !== $profileToken ? $profile->getParentToken() : null;
$childrenToken = array_filter(array_map(function ($p) use ($profileToken) {
return $profileToken !== $p->getToken() ? $p->getToken() : null;
}, $profile->getChildren()));
// Store profile
$data = array(
'token' => $profile->getToken(),
'parent' => $profile->getParentToken(),
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
'token' => $profileToken,
'parent' => $parentToken,
'children' => $childrenToken,
'data' => $profile->getCollectors(),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),