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

Skip to content

Dont allow unserializing classes with a destructor - 4.4 #39794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ private function sendToElasticsearch(array $records)
$this->wait(false);
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
$this->wait(true);
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/ErrorHandler/BufferingLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function cleanLogs(): array
return $logs;
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
foreach ($this->logs as [$level, $message, $context]) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public function didThrow(): bool
return $this->didThrow;
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
if (!$this->didThrow) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ public function reset()
}
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
$this->reset();
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpClient/HttplugClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ public function createUri($uri): UriInterface
throw new \LogicException(sprintf('You cannot use "%s()" as the "nyholm/psr7" package is not installed. Try running "composer require nyholm/psr7".', __METHOD__));
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
$this->wait();
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpClient/Response/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ public function toStream(bool $throw = true)
return $stream;
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

/**
* Closes the response and all its network handles.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ private function checkRestartThreshold(): void
$this->restartCounter = 0;
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
$this->stop();
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Mime/Part/DataPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ public function __wakeup()
$r->setValue($this, $this->_headers);
unset($this->_headers);

if (!\is_array($this->_parent)) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
foreach (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] as $name) {
if (null !== $this->_parent[$name] && !\is_string($this->_parent[$name])) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
$r = new \ReflectionProperty(TextPart::class, $name);
$r->setAccessible(true);
$r->setValue($this, $this->_parent[$name]);
Expand Down