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