Skip to content

Commit 444fb9c

Browse files
authored
Merge pull request #218 from adrienperonnet/backport-fix-cve-2019-18888
Backport fix for cve-2019-18888
2 parents d0df47b + dbe7d74 commit 444fb9c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/validator/sfValidatorFile.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ protected function guessFromFileBinary($file)
263263
{
264264
ob_start();
265265
//need to use --mime instead of -i. see #6641
266-
passthru(sprintf('file -b --mime %s 2>/dev/null', escapeshellarg($file)), $return);
266+
$cmd = 'file -b --mime -- %s 2>/dev/null';
267+
$file = (0 === strpos($file, '-') ? './' : '').$file;
268+
passthru(sprintf($cmd, escapeshellarg($file)), $return);
267269
if ($return > 0)
268270
{
269271
ob_end_clean();

test/unit/validator/sfValidatorFileTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function getMimeTypesFromCategory($category)
106106
$t->is($v->guessFromFileBinary($tmpDir.'/test.txt'), 'text/plain', '->guessFromFileBinary() guesses the type of a given file');
107107
$t->is($v->guessFromFileBinary($tmpDir.'/foo.txt'), null, '->guessFromFileBinary() returns null if the file type is not guessable');
108108
$t->is($v->guessFromFileBinary('/bin/ls'), (PHP_OS != 'Darwin') ? 'application/x-executable' : 'application/octet-stream', '->guessFromFileBinary() returns correct type if file is guessable');
109+
$t->is($v->guessFromFileBinary('-test'), null, '->guessFromFileBinary() returns null if file path has leading dash');
109110

110111
// ->getMimeType()
111112
$t->diag('->getMimeType()');

0 commit comments

Comments
 (0)