Skip to content

Commit

Permalink
Binary-unsafe 'fopen(...)' usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillon-Brown committed Aug 5, 2019
1 parent e56281d commit d7ac85c
Show file tree
Hide file tree
Showing 43 changed files with 96 additions and 95 deletions.
2 changes: 1 addition & 1 deletion SugarSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function display()

public function save($file='')
{
$fp = fopen($file, 'a');
$fp = fopen($file, 'ab');
foreach ($this->results as $result) {
fwrite($fp, $result);
}
Expand Down
2 changes: 1 addition & 1 deletion include/Dashlets/DashletRssFeedTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function readFeed()
if (!in_array(strtolower(parse_url($this->url, PHP_URL_SCHEME)), array("http", "https"), true)) {
return false;
}
$fileOpen = @fopen($this->url, 'r');
$fileOpen = @fopen($this->url, 'rb');
if ($fileOpen) {
$this->fileOpen = true;
$this->contents = fread($fileOpen, $this->readBytes);
Expand Down
4 changes: 2 additions & 2 deletions include/HTMLPurifier/HTMLPurifier.standalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -8232,7 +8232,7 @@ public function parseFile($file)
if (!file_exists($file)) {
return false;
}
$fh = fopen($file, 'r');
$fh = fopen($file, 'rb');
if (!$fh) {
return false;
}
Expand All @@ -8252,7 +8252,7 @@ public function parseMultiFile($file)
return false;
}
$ret = array();
$fh = fopen($file, 'r');
$fh = fopen($file, 'rb');
if (!$fh) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion include/HTTP_WebDAV_Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ public function http_PUT()
}
}

$options["stream"] = fopen("php://input", "r");
$options["stream"] = fopen("php://input", 'rb');

$stat = $this->PUT($options);

Expand Down
2 changes: 1 addition & 1 deletion include/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct($path)
$had_input = false;

// open stream
$f_in = fopen($path, "r");
$f_in = fopen($path, 'rb');
if (!$f_in) {
$this->success = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion include/HTTP_WebDAV_Server/Tools/_parse_propfind.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct($path)
$had_input = false;

// open input stream
$f_in = fopen($path, "r");
$f_in = fopen($path, 'rb');
if (!$f_in) {
$this->success = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion include/HTTP_WebDAV_Server/Tools/_parse_proppatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct($path)
$this->props = array();
$had_input = false;

$f_in = fopen($path, "r");
$f_in = fopen($path, 'rb');
if (!$f_in) {
$this->success = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion include/Imap/ImapHandlerFakeCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
[
'args' => ['{imap.gmail.com:993/service=imap/ssl/tls/validate-cert/secure}INBOX', 'testuser_name', 'testuser_pass', 0, 0, []],
'return' => [function () {
$ret = fopen('fakeImapResource', 'w+'); // <-- create and return a fake resource for InboundEmail test usages
$ret = fopen('fakeImapResource', 'wb+'); // <-- create and return a fake resource for InboundEmail test usages
if (!is_resource($ret)) {
throw new Exception('Imap fake needs a resource to return (check the file permisson - 1)');
}
Expand Down
2 changes: 1 addition & 1 deletion include/Localization/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ public function invalidLocaleNameFormatUpgrade()
*/
public function createInvalidLocaleNameFormatUpgradeNotice()
{
$fh = fopen($this->invalidNameFormatUpgradeFilename, 'w');
$fh = fopen($this->invalidNameFormatUpgradeFilename, 'wb');
fclose($fh);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Smarty/plugins/function.fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function smarty_function_fetch($params, &$smarty)
}

// fetch the file
if ($fp = @fopen($params['file'], 'r')) {
if ($fp = @fopen($params['file'], 'rb')) {
while (!feof($fp)) {
$content .= fgets($fp, 4096);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ function smarty_function_fetch($params, &$smarty)
}
} else {
// ftp fetch
if ($fp = @fopen($params['file'], 'r')) {
if ($fp = @fopen($params['file'], 'rb')) {
while (!feof($fp)) {
$content .= fgets($fp, 4096);
}
Expand Down
2 changes: 1 addition & 1 deletion include/SugarLogger/SugarLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function log(

//if we haven't opened a file pointer yet let's do that
if (! $this->fp) {
$this->fp = fopen($this->full_log_file, 'a');
$this->fp = fopen($this->full_log_file, 'ab');
}


Expand Down
2 changes: 1 addition & 1 deletion include/SugarXHprof/xhprof_lib/utils/xhprof_runs.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function save_run($xhprof_data, $type, $run_id = null)
}

$file_name = $this->file_name($run_id, $type);
$file = fopen($file_name, 'w');
$file = fopen($file_name, 'wb');

if ($file) {
fwrite($file, $xhprof_data);
Expand Down
4 changes: 2 additions & 2 deletions include/externalAPI/ExternalAPIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ public static function loadFullAPIList($forceRebuild=false, $ignoreDisabled = fa

create_cache_directory('/include/');
$cached_tmp = sugar_cached('include/externalAPI.cache-tmp.php');
$fd = fopen($cached_tmp, 'w');
$fd = fopen($cached_tmp, 'wb');
fwrite($fd, "<"."?php\n//This file is auto generated by ".basename(__FILE__)."\n\$fullAPIList = ".var_export($apiFullList, true).";\n\n");
fclose($fd);
rename($cached_tmp, $cached);

$fd = fopen(sugar_cached('include/externalAPI.cache-tmp.js'), 'w');
$fd = fopen(sugar_cached('include/externalAPI.cache-tmp.js'), 'wb');
fwrite($fd, "//This file is auto generated by ".basename(__FILE__)."\nSUGAR.eapm = ".json_encode($apiFullList).";\n\n");
fclose($fd);
rename(sugar_cached('include/externalAPI.cache-tmp.js'), sugar_cached('include/externalAPI.cache.js'));
Expand Down
2 changes: 1 addition & 1 deletion include/language/jsLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function createModuleStringsCache($moduleDir, $lang = 'en_us', $re

$cacheDir = create_cache_directory('jsLanguage/' . $moduleDir . '/');

if ($fh = @fopen($cacheDir . $lang . '.js', "w")) {
if ($fh = @fopen($cacheDir . $lang . '.js', 'wb')) {
fputs($fh, $str);
fclose($fh);
}
Expand Down
2 changes: 1 addition & 1 deletion include/nusoap/class.soap_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function service($data)
} else {
$filename = substr($this->externalWSDLURL, $pos + 7);
}
$fp = fopen($this->externalWSDLURL, 'r');
$fp = fopen($this->externalWSDLURL, 'rb');
fpassthru($fp);
}
} elseif ($this->wsdl) {
Expand Down
6 changes: 3 additions & 3 deletions include/nusoap/class.wsdlcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function get($wsdl)
$this->releaseMutex($filename);
return null;
}
$fp = @fopen($filename, "r");
$fp = @fopen($filename, 'rb');
if ($fp) {
$s = implode("", @file($filename));
fclose($fp);
Expand Down Expand Up @@ -176,7 +176,7 @@ public function obtainMutex($filename, $mode)
$this->debug("Lock for $filename already exists");
return false;
}
$this->fplock[md5($filename)] = fopen($filename.".lock", "w");
$this->fplock[md5($filename)] = fopen($filename.".lock", 'wb');
if ($mode == "r") {
return flock($this->fplock[md5($filename)], LOCK_SH);
}
Expand All @@ -195,7 +195,7 @@ public function put($wsdl_instance)
$filename = $this->createFilename($wsdl_instance->wsdl);
$s = serialize($wsdl_instance);
if ($this->obtainMutex($filename, "w")) {
$fp = fopen($filename, "w");
$fp = fopen($filename, 'wb');
if (! $fp) {
$this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
$this->releaseMutex($filename);
Expand Down
4 changes: 2 additions & 2 deletions include/nusoap/nusoap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5072,7 +5072,7 @@ public function service($data)
} else {
$filename = substr($this->externalWSDLURL, $pos + 7);
}
$fp = fopen($this->externalWSDLURL, 'r');
$fp = fopen($this->externalWSDLURL, 'rb');
fpassthru($fp);
}
} elseif ($this->wsdl) {
Expand Down Expand Up @@ -6392,7 +6392,7 @@ public function parseWSDL($wsdl = '')
$path = $wsdl;
}
$this->debug('getting WSDL file ' . $path);
if ($fp = @fopen($path, 'r')) {
if ($fp = @fopen($path, 'rb')) {
$wsdl_string = '';
while ($data = fread($fp, 32768)) {
$wsdl_string .= $data;
Expand Down
2 changes: 1 addition & 1 deletion include/parsecsv.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ public function _check_count($char, $array, $depth, $preferred)
public function _rfile($file = null)
{
if (is_readable($file)) {
if (!($fh = fopen($file, 'r'))) {
if (!($fh = fopen($file, 'rb'))) {
return false;
}
$data = fread($fh, filesize($file));
Expand Down
2 changes: 1 addition & 1 deletion include/tcpdf/tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14317,7 +14317,7 @@ public function rollbackTransaction()
// truncate files to previous values
foreach ($this->objcopy->cache_file_lenght as $file => $lenght) {
$file = substr($file, 1);
$handle = fopen($file, 'r+');
$handle = fopen($file, 'rb+');
ftruncate($handle, $lenght);
}
}
Expand Down
2 changes: 1 addition & 1 deletion install/install_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ function handleHtaccess()
</IfModule>
EOQ;
if (file_exists($htaccess_file)) {
$fp = fopen($htaccess_file, 'r');
$fp = fopen($htaccess_file, 'rb');
$skip = false;
while ($line = fgets($fp)) {
if (preg_match("/\s*#\s*BEGIN\s*SUGARCRM\s*RESTRICTIONS/i", $line)) {
Expand Down
8 changes: 4 additions & 4 deletions jssource/minify_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ function ConcatenateFiles($from_path)
if (function_exists('sugar_fopen')) {
$trgt_handle = sugar_fopen($trgt, 'a');
} else {
$trgt_handle = fopen($trgt, 'a');
$trgt_handle = fopen($trgt, 'ab');
}
} else {
//open target file
if (function_exists('sugar_fopen')) {
$trgt_handle = sugar_fopen($trgt, 'w');
} else {
$trgt_handle = fopen($trgt, 'w');
$trgt_handle = fopen($trgt, 'wb');
}
}
} else {
Expand All @@ -147,7 +147,7 @@ function ConcatenateFiles($from_path)
if (function_exists('sugar_fopen')) {
$trgt_handle = @sugar_fopen($trgt, 'w');
} else {
$trgt_handle = @fopen($trgt, 'w');
$trgt_handle = @fopen($trgt, 'wb');
}

// todo: make this failure more friendly. Ideally, it will display a
Expand Down Expand Up @@ -268,7 +268,7 @@ function CompressFiles($from_path, $to_path)
if (function_exists('sugar_fopen')) {
$file_handle = sugar_fopen($from_path, 'r');
} else {
$file_handle = fopen($from_path, 'r');
$file_handle = fopen($from_path, 'rb');
}
if ($file_handle) {
$beg = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function loadFromFile($filepath = null)
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('You have to provide valid file path');
}
$fd = fopen($filepath, "r");
$fd = fopen($filepath, 'rb');
if (! $fd) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Cannot open file ' . $filepath);
Expand Down
2 changes: 1 addition & 1 deletion modules/AOD_Index/LuceneUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function createDocXDocument($path)
*/
function createDocDocument($path)
{
$fileHandle = fopen($path, "r");
$fileHandle = fopen($path, 'rb');
$line = @fread($fileHandle, filesize($path));
$lines = explode(chr(0x0D), $line);
$outtext = "";
Expand Down
2 changes: 1 addition & 1 deletion modules/AOR_Charts/lib/pChart/class/pBarcode128.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function pBarcode128($BasePath="")
$this->Codes = "";
$this->Reverse = "";

$FileHandle = @fopen($BasePath."data/128B.db", "r");
$FileHandle = @fopen($BasePath."data/128B.db", 'rb');

if (!$FileHandle) {
die("Cannot find barcode database (".$BasePath."128B.db).");
Expand Down
2 changes: 1 addition & 1 deletion modules/AOR_Charts/lib/pChart/class/pBarcode39.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function pBarcode39($BasePath="", $EnableMOD43=false)
$this->Codes = "";
$this->Reverse = "";

$FileHandle = @fopen($BasePath."data/39.db", "r");
$FileHandle = @fopen($BasePath."data/39.db", 'rb');

if (!$FileHandle) {
die("Cannot find barcode database (".$BasePath."data/39.db).");
Expand Down
22 changes: 11 additions & 11 deletions modules/AOR_Charts/lib/pChart/class/pCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ public function writeToCache($ID, $pChartObject)
$DBSize = filesize($Database);

/* Save the index */
$Handle = fopen($Index, "a");
$Handle = fopen($Index, 'ab');
fwrite($Handle, $ID.",".$DBSize.",".$PictureSize.",".time().",0 \r\n");
fclose($Handle);

/* Get the picture raw contents */
$Handle = fopen($TemporaryFile, "r");
$Handle = fopen($TemporaryFile, 'rb');
$Raw = fread($Handle, $PictureSize);
fclose($Handle);

/* Save the picture in the solid database file */
$Handle = fopen($Database, "a");
$Handle = fopen($Database, 'ab');
fwrite($Handle, $Raw);
fclose($Handle);

Expand Down Expand Up @@ -137,10 +137,10 @@ public function dbRemoval($Settings)
}

/* Open the file handles */
$IndexHandle = @fopen($Index, "r");
$IndexTempHandle = @fopen($IndexTemp, "w");
$DBHandle = @fopen($Database, "r");
$DBTempHandle = @fopen($DatabaseTemp, "w");
$IndexHandle = @fopen($Index, 'rb');
$IndexTempHandle = @fopen($IndexTemp, 'wb');
$DBHandle = @fopen($Database, 'rb');
$DBTempHandle = @fopen($DatabaseTemp, 'wb');

/* Remove the selected ID from the database */
while (!feof($IndexHandle)) {
Expand Down Expand Up @@ -188,7 +188,7 @@ public function isInCache($ID, $Verbose=false, $UpdateHitsCount=false)
$Index = $this->CacheFolder."/".$this->CacheIndex;

/* Search the picture in the index file */
$Handle = @fopen($Index, "r");
$Handle = @fopen($Index, 'rb');
while (!feof($Handle)) {
$IndexPos = ftell($Handle);
$Entry = fgets($Handle, 4096);
Expand All @@ -209,7 +209,7 @@ public function isInCache($ID, $Verbose=false, $UpdateHitsCount=false)
$Hits = $Hits.str_repeat(" ", 7-strlen($Hits));
}

$Handle = @fopen($Index, "r+");
$Handle = @fopen($Index, 'rb+');
fseek($Handle, $IndexPos);
fwrite($Handle, $PicID.",".$DBPos.",".$PicSize.",".$GeneratedTS.",".$Hits."\r\n");
fclose($Handle);
Expand Down Expand Up @@ -265,7 +265,7 @@ public function saveFromCache($ID, $Destination)
}

/* Flush the picture to a file */
$Handle = fopen($Destination, "w");
$Handle = fopen($Destination, 'wb');
fwrite($Handle, $Picture);
fclose($Handle);

Expand All @@ -291,7 +291,7 @@ public function getFromCache($ID)
$PicSize = $CacheInfo["PicSize"];

/* Extract the picture from the solid cache file */
$Handle = @fopen($Database, "r");
$Handle = @fopen($Database, 'rb');
fseek($Handle, $DBPos);
$Picture = fread($Handle, $PicSize);
fclose($Handle);
Expand Down
4 changes: 2 additions & 2 deletions modules/AOR_Charts/lib/pChart/class/pData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public function loadPalette($FileName, $Overwrite=false)
$this->Palette = "";
}

$fileHandle = @fopen($FileName, "r");
$fileHandle = @fopen($FileName, 'rb');
if (!$fileHandle) {
return(-1);
}
Expand Down Expand Up @@ -867,7 +867,7 @@ public function importFromCSV($FileName, $Options="")
$SkipColumns = isset($Options["SkipColumns"]) ? $Options["SkipColumns"] : array(-1);
$DefaultSerieName = isset($Options["DefaultSerieName"]) ? $Options["DefaultSerieName"] : "Serie";

$Handle = @fopen($FileName, "r");
$Handle = @fopen($FileName, 'rb');
if ($Handle) {
$HeaderParsed = false;
$SerieNames = "";
Expand Down
Loading

0 comments on commit d7ac85c

Please sign in to comment.