Skip to content

Commit

Permalink
MDL-55724 Glossary: Prevent infinite loop in trusttext_strip
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Aug 30, 2016
1 parent 95839d6 commit 297486d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/weblib.php
Expand Up @@ -1583,6 +1583,10 @@ function strip_pluginfile_content($source) {
* @return string text without legacy TRUSTTEXT marker
*/
function trusttext_strip($text) {
if (!is_string($text)) {
// This avoids the potential for an endless loop below.
throw new coding_exception('trusttext_strip parameter must be a string');
}
while (true) { // Removing nested TRUSTTEXT.
$orig = $text;
$text = str_replace('#####TRUSTTEXT#####', '', $text);
Expand Down
6 changes: 5 additions & 1 deletion mod/glossary/import.php
Expand Up @@ -170,7 +170,11 @@
$xmlentry = $xmlentries[$i];
$newentry = new stdClass();
$newentry->concept = trim($xmlentry['#']['CONCEPT'][0]['#']);
$newentry->definition = trusttext_strip($xmlentry['#']['DEFINITION'][0]['#']);
$definition = $xmlentry['#']['DEFINITION'][0]['#'];
if (!is_string($definition)) {
print_error('errorparsingxml', 'glossary');
}
$newentry->definition = trusttext_strip($definition);
if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) {
$newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#'];
} else {
Expand Down

0 comments on commit 297486d

Please sign in to comment.