Skip to content

Commit 73a70ac

Browse files
Merge branch '4.4' into 5.1
* 4.4: Dont allow unserializing classes with a destructor Dont allow unserializing classes with a destructor - 4.4 [Cache] fix possible collision when writing tmp file in filesystem adapter a colon followed by spaces exclusively separates mapping keys and values Contracts: Remove ellipsis fix handling float-like key attribute values Fix missing BCC recipients in SES bridge
2 parents 8bc5679 + e6cfa09 commit 73a70ac

File tree

30 files changed

+280
-7
lines changed

30 files changed

+280
-7
lines changed

src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ private function sendToElasticsearch(array $records)
129129
$this->wait(false);
130130
}
131131

132+
public function __sleep()
133+
{
134+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
135+
}
136+
137+
public function __wakeup()
138+
{
139+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
140+
}
141+
132142
public function __destruct()
133143
{
134144
$this->wait(true);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ public function __sleep(): array
8989

9090
public function __wakeup()
9191
{
92+
foreach ($this as $k => $v) {
93+
if (\is_object($v)) {
94+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
95+
}
96+
}
97+
9298
$this->__construct($this->varDir, $this->testCase, $this->rootConfig, $this->environment, $this->debug);
9399
}
94100

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,20 @@ private function write(string $file, string $data, int $expiresAt = null)
9393
set_error_handler(__CLASS__.'::throwError');
9494
try {
9595
if (null === $this->tmp) {
96-
$this->tmp = $this->directory.uniqid('', true);
96+
$this->tmp = $this->directory.bin2hex(random_bytes(6));
9797
}
98-
file_put_contents($this->tmp, $data);
98+
try {
99+
$h = fopen($this->tmp, 'x');
100+
} catch (\ErrorException $e) {
101+
if (false === strpos($e->getMessage(), 'File exists')) {
102+
throw $e;
103+
}
104+
105+
$this->tmp = $this->directory.bin2hex(random_bytes(6));
106+
$h = fopen($this->tmp, 'x');
107+
}
108+
fwrite($h, $data);
109+
fclose($h);
99110

100111
if (null !== $expiresAt) {
101112
touch($this->tmp, $expiresAt);

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ protected function normalizeValue($value)
227227
} elseif (isset($v[$this->keyAttribute])) {
228228
$k = $v[$this->keyAttribute];
229229

230+
if (\is_float($k)) {
231+
$k = var_export($k, true);
232+
}
233+
230234
// remove the key attribute when required
231235
if ($this->removeKeyAttribute) {
232236
unset($v[$this->keyAttribute]);

src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,32 @@ public function testAssociativeArrayPreserveKeys()
201201
$this->assertNormalized($tree, $data, $data);
202202
}
203203

204+
public function testFloatLikeValueAsMapKeyAttribute()
205+
{
206+
$tree = (new TreeBuilder('root'))
207+
->getRootNode()
208+
->useAttributeAsKey('number')
209+
->arrayPrototype()
210+
->children()
211+
->scalarNode('foo')->end()
212+
->end()
213+
->end()
214+
->end()
215+
->buildTree()
216+
;
217+
218+
$this->assertNormalized($tree, [
219+
[
220+
'number' => 3.0,
221+
'foo' => 'bar',
222+
],
223+
], [
224+
'3.0' => [
225+
'foo' => 'bar',
226+
],
227+
]);
228+
}
229+
204230
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
205231
{
206232
self::assertSame($normalized, $tree->normalize($denormalized));

src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public function __call(string $method, array $args)
4040
throw new \BadMethodCallException(sprintf('Call to undefined method "%s::%s()".', static::class, $method));
4141
}
4242

43+
public function __sleep()
44+
{
45+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
46+
}
47+
48+
public function __wakeup()
49+
{
50+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
51+
}
52+
4353
/**
4454
* Checks that a value is valid, optionally replacing Definition and Reference configurators by their configure value.
4555
*

src/Symfony/Component/ErrorHandler/BufferingLogger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public function cleanLogs(): array
3535
return $logs;
3636
}
3737

38+
public function __sleep()
39+
{
40+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
41+
}
42+
43+
public function __wakeup()
44+
{
45+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
46+
}
47+
3848
public function __destruct()
3949
{
4050
foreach ($this->logs as [$level, $message, $context]) {

src/Symfony/Component/Form/Util/OrderedHashMapIterator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public function __construct(array &$elements, array &$orderedKeys, array &$manag
7676
$this->managedCursors[$this->cursorId] = &$this->cursor;
7777
}
7878

79+
public function __sleep()
80+
{
81+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
82+
}
83+
84+
public function __wakeup()
85+
{
86+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
87+
}
88+
7989
/**
8090
* Removes the iterator's cursors from the managed cursors of the
8191
* corresponding {@link OrderedHashMap} instance.

src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public function didThrow(): bool
116116
return $this->didThrow;
117117
}
118118

119+
public function __sleep()
120+
{
121+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
122+
}
123+
124+
public function __wakeup()
125+
{
126+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
127+
}
128+
119129
public function __destruct()
120130
{
121131
if (!$this->didThrow) {

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ public function reset()
362362
}
363363
}
364364

365+
public function __sleep()
366+
{
367+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
368+
}
369+
370+
public function __wakeup()
371+
{
372+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
373+
}
374+
365375
public function __destruct()
366376
{
367377
$this->reset();

0 commit comments

Comments
 (0)