Skip to content

Commit 332b6f0

Browse files
committed
bug #57305 [Validator] do not modify a constraint during validation to not leak its context (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [Validator] do not modify a constraint during validation to not leak its context | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57301 | License | MIT Commits ------- 34c12b7 do not modify a constraint during validation to not leak its context
2 parents ecd1d92 + 34c12b7 commit 332b6f0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/Validator/Constraints/CidrValidator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ public function validate($value, Constraint $constraint): void
7171
return;
7272
}
7373

74-
if (filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4) && $constraint->netmaskMax > 32) {
75-
$constraint->netmaskMax = 32;
74+
$netmaskMax = $constraint->netmaskMax;
75+
76+
if (filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4) && $netmaskMax > 32) {
77+
$netmaskMax = 32;
7678
}
7779

78-
if ($netmask < $constraint->netmaskMin || $netmask > $constraint->netmaskMax) {
80+
if ($netmask < $constraint->netmaskMin || $netmask > $netmaskMax) {
7981
$this->context
8082
->buildViolation($constraint->netmaskRangeViolationMessage)
8183
->setParameter('{{ min }}', $constraint->netmaskMin)

src/Symfony/Component/Validator/Tests/Constraints/CidrValidatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,17 @@ public static function getWithWrongVersion(): array
255255
['2001:0db8:85a3:0000:0000:8a2e:0370:7334/13', Ip::V4],
256256
];
257257
}
258+
259+
public function testDoesNotModifyContextBetweenValidations()
260+
{
261+
$constraint = new Cidr();
262+
263+
$this->validator->validate('1.2.3.4/28', $constraint);
264+
265+
$this->assertNoViolation();
266+
267+
$this->validator->validate('::1/64', $constraint);
268+
269+
$this->assertNoViolation();
270+
}
258271
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy