Skip to content

Commit 037bd3c

Browse files
committed
CRM-19013 - Smarty - Use SHA-256 to generate compiled template filenames.
1 parent e123713 commit 037bd3c

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

Smarty/Smarty.class.php

+3-38
Original file line numberDiff line numberDiff line change
@@ -1516,42 +1516,9 @@ function _get_compile_path($resource_name)
15161516
$this->_compile_id );
15171517
$compilePath .= '.php';
15181518

1519-
//for 'string:' resource smarty might going to fail to create
1520-
//compile file, so make sure we should have valid path, CRM-5890
1521-
$matches = array( );
1522-
if ( preg_match( '/^(\s+)?string:/', $resource_name, $matches ) ) {
1523-
if ( !$this->validateCompilePath( $compilePath ) ) {
1524-
$compilePath = $this->_get_auto_filename( $this->compile_dir,
1525-
time().rand(),
1526-
$this->_compile_id );
1527-
$compilePath .= '.php';
1528-
}
1529-
}
1530-
15311519
return $compilePath;
15321520
}
15331521

1534-
/**
1535-
* do check can smarty create a file w/ given path.
1536-
*/
1537-
function validateCompilePath( $compilePath ) {
1538-
//first check for directory.
1539-
$dirname = dirname( $compilePath );
1540-
if ( !is_dir( $dirname ) ) {
1541-
require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
1542-
smarty_core_create_dir_structure( array('dir' => $dirname ), $this );
1543-
}
1544-
1545-
$isValid = false;
1546-
if ( $fd = @fopen( $compilePath, 'wb') ) {
1547-
$isValid = true;
1548-
@fclose( $fd );
1549-
@unlink($compilePath);
1550-
}
1551-
1552-
return $isValid;
1553-
}
1554-
15551522
/**
15561523
* fetch the template info. Gets timestamp, and source
15571524
* if get_source is true
@@ -1786,13 +1753,11 @@ function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
17861753

17871754
if(isset($auto_source)) {
17881755
// make source name safe for filename
1789-
$_filename = urlencode(basename($auto_source));
1790-
$_crc32 = sprintf('%08X', crc32($auto_source));
1756+
$_sha256 = hash('sha256', $auto_source);
17911757
// prepend %% to avoid name conflicts with
17921758
// with $params['auto_id'] names
1793-
$_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .
1794-
substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
1795-
$_return .= '%%' . $_crc32 . '%%' . $_filename;
1759+
$_return .= '%%' . substr($_sha256, 0, 2) . $_compile_dir_sep .
1760+
substr($_sha256, 0, 3) . $_compile_dir_sep . $_sha256;
17961761
}
17971762

17981763
return $_return;

0 commit comments

Comments
 (0)