From 599e1a877bdceec5afc080b3218b6d51fd9363fa Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 25 Aug 2016 17:04:11 +0100 Subject: [PATCH] MDL-55724 Glossary: Prevent infinite loop in trusttext_strip --- lib/weblib.php | 4 ++++ mod/glossary/import.php | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/weblib.php b/lib/weblib.php index e80d488ea3f..9a193421207 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1538,6 +1538,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); diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 87783e74516..f377d0765e7 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -170,7 +170,11 @@ if ($xml = glossary_read_imported_file($result)) { $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 {