Skip to content
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

Check for null byte at the time of writing a file. #966

Merged
Merged
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
10 changes: 5 additions & 5 deletions lib/Varien/Io/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ public function write($filename, $src, $mode=null)
*/
protected function _IsValidSource($src)
{
if (is_string($src) || is_resource($src)) {
//Treat string that contains a null byte as invalid
if ((is_string($src) && strpos($src, char(0)) === false) || is_resource($src)) {
return true;
}

Expand All @@ -505,7 +506,7 @@ protected function _isFilenameWriteable($filename)
{
$error = false;
@chdir($this->_cwd);
if (file_exists($filename)) {
if (file_exists($filename)) {
if (!is_writeable($filename)) {
$error = "File '{$this->getFilteredPath($filename)}' isn't writeable";
}
Expand All @@ -532,8 +533,7 @@ protected function _isFilenameWriteable($filename)
protected function _checkSrcIsFile($src)
{
$result = false;
// both is_readable() and is_file() emit E_WARNING if there is a null byte in $src
if (is_string($src) && @is_readable($src) && @is_file($src)) {
if (is_string($src) && is_readable($src) && is_file($src)) {
$result = true;
}

Expand Down Expand Up @@ -846,7 +846,7 @@ public function dirname($file)
{
return $this->getCleanPath(dirname($file));
}

public function getStreamHandler()
{
return $this->_streamHandler;
Expand Down