Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f7c2d5

Browse files
committed
Prevent infinite loop in PropertyMetadata
1 parent 8794617 commit 9f7c2d5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/Validator/Mapping/PropertyMetadata.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ public function getPropertyValue($object)
5858
*/
5959
protected function newReflectionMember($objectOrClassName)
6060
{
61+
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
62+
6163
while (!property_exists($objectOrClassName, $this->getName())) {
6264
$objectOrClassName = get_parent_class($objectOrClassName);
65+
66+
if (false === $objectOrClassName) {
67+
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s"', $this->getName(), $originalClass));
68+
}
6369
}
6470

6571
$member = new \ReflectionProperty($objectOrClassName, $this->getName());

src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ public function testGetPropertyValueFromOverriddenPrivateProperty()
4242
$this->assertTrue($metadata->isPublic($entity));
4343
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
4444
}
45+
46+
public function testGetPropertyValueFromRemovedProperty()
47+
{
48+
$entity = new Entity('foobar');
49+
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
50+
$metadata->name = 'test';
51+
52+
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
53+
$metadata->getPropertyValue($entity);
54+
}
4555
}

0 commit comments

Comments
 (0)