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

Skip to content

Commit d5d388f

Browse files
bug #39796 Dont allow unserializing classes with a destructor - 5.2 (jderusse)
This PR was merged into the 5.2 branch. Discussion ---------- Dont allow unserializing classes with a destructor - 5.2 | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Prevent destructors with side-effects from being unserialized Commits ------- 9860190 Dont allow unserializing classes with a destructor - 5.2
2 parents 5dff21b + 9860190 commit d5d388f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Symfony/Component/HttpClient/Response/CommonResponseTrait.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public function toStream(bool $throw = true)
127127
return $stream;
128128
}
129129

130+
public function __sleep()
131+
{
132+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
133+
}
134+
135+
public function __wakeup()
136+
{
137+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
138+
}
139+
130140
/**
131141
* Closes the response and all its network handles.
132142
*/

src/Symfony/Component/HttpClient/Response/TraceableResponse.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public function __construct(HttpClientInterface $client, ResponseInterface $resp
4444
$this->event = $event;
4545
}
4646

47+
public function __sleep()
48+
{
49+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
50+
}
51+
52+
public function __wakeup()
53+
{
54+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
55+
}
56+
4757
public function __destruct()
4858
{
4959
try {

src/Symfony/Component/RateLimiter/Policy/TokenBucket.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function __sleep(): array
104104
*/
105105
public function __wakeup(): void
106106
{
107+
if (!\is_string($this->stringRate)) {
108+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
109+
}
110+
107111
$this->rate = Rate::fromString($this->stringRate);
108112
unset($this->stringRate);
109113
}

0 commit comments

Comments
 (0)