Skip to content

Commit c9f2985

Browse files
damien-biasottoedannenberg
authored andcommitted
[impr-OpenMage#966] Prevent filename with null byte(s) in Varien_Io_File
1 parent 70cce30 commit c9f2985

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/Varien/Io/File.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ public function write($filename, $src, $mode=null)
486486
*/
487487
protected function _IsValidSource($src)
488488
{
489-
if (is_string($src) || is_resource($src)) {
489+
//Treat string that contains a null byte as invalid
490+
if ((is_string($src) && strpos($src, chr(0)) === false) || is_resource($src)) {
490491
return true;
491492
}
492493

@@ -505,7 +506,7 @@ protected function _isFilenameWriteable($filename)
505506
{
506507
$error = false;
507508
@chdir($this->_cwd);
508-
if (file_exists($filename)) {
509+
if (file_exists($filename)) {
509510
if (!is_writeable($filename)) {
510511
$error = "File '{$this->getFilteredPath($filename)}' isn't writeable";
511512
}
@@ -532,7 +533,7 @@ protected function _isFilenameWriteable($filename)
532533
protected function _checkSrcIsFile($src)
533534
{
534535
$result = false;
535-
if (is_string($src) && @is_readable($src) && is_file($src)) {
536+
if (is_string($src) && is_readable($src) && is_file($src)) {
536537
$result = true;
537538
}
538539

@@ -845,7 +846,7 @@ public function dirname($file)
845846
{
846847
return $this->getCleanPath(dirname($file));
847848
}
848-
849+
849850
public function getStreamHandler()
850851
{
851852
return $this->_streamHandler;

0 commit comments

Comments
 (0)