Skip to content

Commit

Permalink
Merge pull request #35 from sugarcrm/BR-5649
Browse files Browse the repository at this point in the history
BR-5649: Fix fread corruption if string consumed from stream was smal…
  • Loading branch information
zsprackett authored Sep 19, 2017
2 parents 6297a39 + 056e833 commit 5216843
Show file tree
Hide file tree
Showing 4 changed files with 480 additions and 11 deletions.
4 changes: 2 additions & 2 deletions shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ static void shadow_fread(INTERNAL_FUNCTION_PARAMETERS)
php_stream_from_zval(stream, arg1);
if(stream->wrapper == &shadow_wrapper) {
zend_string *contents = NULL;
int newlen;

if (len <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
Expand All @@ -1223,7 +1222,8 @@ static void shadow_fread(INTERNAL_FUNCTION_PARAMETERS)

contents = php_stream_copy_to_mem(stream, len, 0);
if (contents) {
RETVAL_STRINGL(ZSTR_VAL(contents), len);

RETVAL_STRINGL(ZSTR_VAL(contents), contents->len);
efree(contents);
} else {
RETVAL_EMPTY_STRING();
Expand Down
89 changes: 89 additions & 0 deletions tests/fread.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--TEST--
Check fread with specific length
--SKIPIF--
<?php if (!extension_loaded("shadow")) print "skip"; ?>
--FILE--
<?php
require_once('setup.inc');
$f = fopen("$template/manifest.php", 'r');
fread($f, 8192);
fread($f, 8192);
$data = fread($f, 8192);
var_dump($data);

?>
--EXPECT--
string(2440) " 'audited' => '1',
'mass_update' => '0',
'duplicate_merge' => '1',
'reportable' => '1',
'importable' => 'true',
'ext1' => null,
'ext2' => null,
'ext3' => null,
'ext4' => null,
),
'Leadsmrkto2_annualrevenue_c' =>
array(
'id' => 'Leadsmrkto2_annualrevenue_c',
'name' => 'mrkto2_annualrevenue_c',
'label' => 'LBL_MRKTO2_ANNUALREVENUE_C',
'comments' => null,
'help' => null,
'module' => 'Leads',
'type' => 'currency',
'max_size' => '26',
'require_option' => '0',
'default_value' => null,
'date_modified' => '2010-05-04 14:52:58',
'deleted' => '0',
'audited' => '1',
'mass_update' => '0',
'duplicate_merge' => '1',
'reportable' => '1',
'importable' => 'true',
'ext1' => null,
'ext2' => null,
'ext3' => null,
'ext4' => null,
),
)
);
foreach ($coreFiles as $file) {
$installdefs['copy'][] =
array(
'from' => "<basepath>/$file",
'to' => $file,
);
}
foreach ($extraFiles as $file) {
$installdefs['copy'][] =
array(
'from' => "<basepath>/$file",
'to' => $file,
);
}

if (version_compare($sugar_version, '7.0.0') < 0) {
foreach ($coreFiles as $file) {
$pos = strpos($file, 'Ext');
if ($pos !== false) {
$installdefs['copy'][] =
array(
'from' => "<basepath>/$file",
'to' => ($pos == 0) ? "custom/Extension/application/$file" : "custom/Extension/$file",
);
}
}

foreach ($sugar6Files as $file) {
$installdefs['copy'][] =
array(
'from' => "<basepath>/$file",
'to' => $file,
);
}
}
"


Loading

0 comments on commit 5216843

Please sign in to comment.