Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-release-src > by-pkgid > 56babb1dbb9ebbdc311068866e01a1bf > files > 43

moodle-1.9.5-2mdv2010.1.src.rpm

--- filter/tex/filter.php	2008-04-24 02:17:12.000000000 +0200
+++ filter/tex/filter.php.oden	2009-03-31 10:14:04.000000000 +0200
@@ -123,6 +123,16 @@ function tex_filter ($courseid, $text) {
         $text = str_replace($matches[0][$i],$replacement,$text);
     }
 
+    // TeX blacklist. MDL-18552
+    $tex_blacklist = array(
+        'include','def','command','loop','repeat','open','toks','output',
+        'input','catcode','name','^^',
+        '\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
+        '\batchmode','\read','\write','csname','\newhelp','\uppercase',
+        '\lowercase','\relax','\aftergroup',
+        '\afterassignment','\expandafter','\noexpand','\special'
+    );
+
     // <tex> TeX expression </tex>
     // or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
     // or $$ TeX expression $$
@@ -145,6 +155,19 @@ function tex_filter ($courseid, $text) {
           $align = "text-top";
           $texexp = preg_replace('/^align=top /','',$texexp);
         }
+    /// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain). MDL-18552
+        $invalidcommands = array();
+        foreach($tex_blacklist as $command) {
+            if (stristr($texexp, $command)) { /// Found invalid command. Annotate.
+                $invalidcommands[] = $command;
+            }
+        }
+        if (!empty($invalidcommands)) { /// Invalid commands found. Output error and continue with next TeX element
+            $invalidstr = get_string('invalidtexcommand', 'error', implode(', ', $invalidcommands));
+            $text = str_replace( $matches[0][$i], $invalidstr, $text);
+            continue;
+        }
+    /// Everything is ok, let's process the expression
         $md5 = md5($texexp);
         if (! $texcache = get_record("cache_filters","filter","tex", "md5key", $md5)) {
             $texcache->filter = 'tex';