Skip to content

Commit

Permalink
Don't trust properties at destruct time
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 9, 2020
1 parent f7d2961 commit 5878b18
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/classes/Swift/ByteStream/TemporaryFileByteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public function __destruct()
@unlink($this->getPath());
}
}

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

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
}
5 changes: 5 additions & 0 deletions lib/classes/Swift/KeyCache/DiskKeyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,9 @@ public function __destruct()
$this->clearAll($nsKey);
}
}

public function __wakeup()
{
$this->keys = [];
}
}
6 changes: 6 additions & 0 deletions lib/classes/Swift/Mime/SimpleMimeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,10 @@ public function __clone()
}
$this->setChildren($children);
}

public function __wakeup()
{
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
$this->cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream());
}
}
10 changes: 10 additions & 0 deletions lib/classes/Swift/Transport/AbstractSmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,14 @@ public function __destruct()
} catch (Exception $e) {
}
}

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

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

0 comments on commit 5878b18

Please sign in to comment.