Skip to content

Commit 24c8f83

Browse files
PHP: Fixed exponential runtime of a pattern (#2157)
This fixes the exponential runtime of the pattern used to identify PHP code embedded in HTML.
1 parent 199bdca commit 24c8f83

File tree

3 files changed

+127
-2
lines changed

3 files changed

+127
-2
lines changed

components/prism-php.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
return;
120120
}
121121

122-
var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
122+
var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
123123
Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
124124
});
125125

components/prism-php.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/php/issue2156.test

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?
2+
// Session starten und confog.php includen
3+
session_start();
4+
include ("config.php");
5+
6+
// CaptchaCodes abfragen
7+
$CAPTCHA_RandomText = "";
8+
if (isset($_POST['txtCode'])){
9+
$CAPTCHA_EnteredText = str_replace("<","",str_replace(">","",str_replace("'","",str_replace("[","",str_replace("]","",$_POST['txtCode'])))));
10+
}
11+
if (isset($_SESSION['CAPTCHA_RndText'])) {
12+
$CAPTCHA_RandomText = $_SESSION['CAPTCHA_RndText'];
13+
}
14+
15+
// Eingabefelder abfragen
16+
$_SESSION['company'] = $_POST['company'];
17+
$_SESSION['name'] = $_POST['name'];
18+
$_SESSION['address'] = $_POST['address'];
19+
$_SESSION['zip_code'] = $_POST['zip_code'];
20+
$_SESSION['city'] = $_POST['city'];
21+
$_SESSION['county'] = $_POST['county'];
22+
$_SESSION['country'] = $_POST['country'];
23+
$_SESSION['phone'] = $_POST['phone'];
24+
$_SESSION['fax'] = $_POST['fax'];
25+
$_SESSION['email'] = $_POST['email'];
26+
$_SESSION['nachricht'] = $_POST['nachricht'];
27+
28+
$email_i = $_SESSION['email'];
29+
30+
// Email Funktion
31+
function pruefe_mail($email_i) {
32+
if(strstr($email_i, "@")) {
33+
$email_i = explode ("@", $email_i);
34+
if(strstr($email_i[1], ".")) $ok = TRUE;
35+
}
36+
return $ok;
37+
}
38+
39+
// Eingaben prüfen
40+
$fehler = "";
41+
if(!pruefe_mail($email_i) && !empty($email_i)) {
42+
$fehler .= "<li>email</li>";
43+
}
44+
if ($_SESSION['name'] == ""){
45+
$fehler .= "<li>name</li>";
46+
}
47+
if ($_SESSION['city'] == ""){
48+
$fehler .= "<li>city</li>";
49+
}
50+
if ($_SESSION['country'] == ""){
51+
$fehler .= "<li>country</li>";
52+
}
53+
if ($_SESSION['phone'] == ""){
54+
$fehler .= "<li>phone</li>";
55+
}
56+
if ($_SESSION['email'] == ""){
57+
$fehler .= "<li>email</li>";
58+
}
59+
if ($_SESSION['message'] == ""){
60+
$fehler .= "<li>message</li>";
61+
}
62+
if ($CAPTCHA_EnteredText == $CAPTCHA_RandomText and isset($_POST['txtCode']) == true and isset($_SESSION['CAPTCHA_RndText'])){
63+
$captcha = true;
64+
} else {
65+
$fehler .= "<li>code</li>";
66+
}
67+
echo '<div>';
68+
if ($fehler == ""){
69+
// Email zumsammensetzen
70+
$email = "From: " . $_SESSION['email'];
71+
72+
73+
$nachrichtfertig =
74+
"Company: " . $_SESSION['company'] "n\"
75+
"Name: " $_SESSION['name'] "n\"
76+
"Address: " $_SESSION['address'] "n\"
77+
"ZIP Code: " $_SESSION['zip_code'] "n\"
78+
"City: " $_SESSION['city'] "n\"
79+
"County: " $_SESSION['county'] "n\"
80+
"Country: " $_SESSION['country'] "n\"
81+
"Phone: " $_SESSION['phone'] "n\"
82+
"Fax: " $_SESSION['fax'] "n\"
83+
"eMail: " $_SESSION['email'] "n\n\"
84+
"Message: " $_SESSION['message'];
85+
86+
87+
$versand = mail($empfaenger, $betreff, $nachrichtfertig, $email);
88+
if ($versand) {
89+
echo '<p class=titles>Thank you very much!</p>
90+
<p>The message were send successfully</p>';
91+
92+
// Sessionvariablen löschen
93+
unset($_SESSION['company']);
94+
unset($_SESSION['name']);
95+
unset($_SESSION['address']);
96+
unset($_SESSION['zip_code']);
97+
unset($_SESSION['city']);
98+
unset($_SESSION['county']);
99+
unset($_SESSION['country']);
100+
unset($_SESSION['phone']);
101+
unset($_SESSION['fax']);
102+
unset($_SESSION['email']);
103+
unset($_SESSION['nachricht']);
104+
}
105+
106+
} else {
107+
echo '<p class=titles>Error</p>';
108+
echo '<p>Please fill in all the $fehler field. <a href="contact.php">back</a></p>';
109+
}
110+
echo '</div>';
111+
112+
// Session unset
113+
unset($_SESSION['CAPTCHA_RndText']);
114+
115+
?>
116+
117+
----------------------------------------------------
118+
119+
[
120+
["prolog", "<?\n\t// Session starten und confog.php includen\n\tsession_start();\n\tinclude (\"config.php\");\n\n\t// CaptchaCodes abfragen\n\t$CAPTCHA_RandomText = \"\";\n\tif (isset($_POST['txtCode'])){\n\t$CAPTCHA_EnteredText = str_replace(\"<\",\"\",str_replace(\">\",\"\",str_replace(\"'\",\"\",str_replace(\"[\",\"\",str_replace(\"]\",\"\",$_POST['txtCode'])))));\n\t}\n\tif (isset($_SESSION['CAPTCHA_RndText'])) {\n\t$CAPTCHA_RandomText = $_SESSION['CAPTCHA_RndText'];\n\t}\n\n\t// Eingabefelder abfragen\n\t$_SESSION['company'] = $_POST['company'];\n\t$_SESSION['name'] = $_POST['name'];\n\t$_SESSION['address'] = $_POST['address'];\n\t$_SESSION['zip_code'] = $_POST['zip_code'];\n\t$_SESSION['city'] = $_POST['city'];\n\t$_SESSION['county'] = $_POST['county'];\n\t$_SESSION['country'] = $_POST['country'];\n\t$_SESSION['phone'] = $_POST['phone'];\n\t$_SESSION['fax'] = $_POST['fax'];\n\t$_SESSION['email'] = $_POST['email'];\n\t$_SESSION['nachricht'] = $_POST['nachricht'];\n\n\t$email_i = $_SESSION['email'];\n\n\t// Email Funktion\n\tfunction pruefe_mail($email_i) {\n\t\t if(strstr($email_i, \"@\")) {\n\t\t\t$email_i = explode (\"@\", $email_i);\n\t\t\tif(strstr($email_i[1], \".\")) $ok = TRUE;\n\t\t }\n\t\t return $ok;\n\t\t}\n\n\t// Eingaben prüfen\n\t$fehler = \"\";\n\tif(!pruefe_mail($email_i) && !empty($email_i)) {\n\t\t\t$fehler .= \"<li>email</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['name'] == \"\"){\n\t\t\t$fehler .= \"<li>name</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['city'] == \"\"){\n\t\t\t$fehler .= \"<li>city</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['country'] == \"\"){\n\t\t\t$fehler .= \"<li>country</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['phone'] == \"\"){\n\t\t\t$fehler .= \"<li>phone</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['email'] == \"\"){\n\t\t\t$fehler .= \"<li>email</li>\";\n\t\t\t}\n\t\t\tif ($_SESSION['message'] == \"\"){\n\t\t\t$fehler .= \"<li>message</li>\";\n\t\t\t}\n\t\t\tif ($CAPTCHA_EnteredText == $CAPTCHA_RandomText and isset($_POST['txtCode']) == true and isset($_SESSION['CAPTCHA_RndText'])){\n\t\t\t$captcha = true;\n\t\t\t} else {\n\t\t\t$fehler .= \"<li>code</li>\";\n\t\t\t}\n\techo '<div>';\n\tif ($fehler == \"\"){\n\t// Email zumsammensetzen\n\t$email = \"From: \" . $_SESSION['email'];\n\n\n\t$nachrichtfertig =\n\t\"Company: \" . $_SESSION['company'] \"n\\\"\n\t\"Name: \" $_SESSION['name'] \"n\\\"\n\t\"Address: \" $_SESSION['address'] \"n\\\"\n\t\"ZIP Code: \" $_SESSION['zip_code'] \"n\\\"\n\t\"City: \" $_SESSION['city'] \"n\\\"\n\t\"County: \" $_SESSION['county'] \"n\\\"\n\t\"Country: \" $_SESSION['country'] \"n\\\"\n\t\"Phone: \" $_SESSION['phone'] \"n\\\"\n\t\"Fax: \" $_SESSION['fax'] \"n\\\"\n\t\"eMail: \" $_SESSION['email'] \"n\\n\\\"\n\t\"Message: \" $_SESSION['message'];\n\n\n\t$versand = mail($empfaenger, $betreff, $nachrichtfertig, $email);\n\t\t\tif ($versand) {\n\t\t\techo '<p class=titles>Thank you very much!</p>\n\t\t\t\t <p>The message were send successfully</p>';\n\n\t\t\t// Sessionvariablen löschen\n\t\t\tunset($_SESSION['company']);\n\t\t\tunset($_SESSION['name']);\n\t\t\tunset($_SESSION['address']);\n\t\t\tunset($_SESSION['zip_code']);\n\t\t\tunset($_SESSION['city']);\n\t\t\tunset($_SESSION['county']);\n\t\t\tunset($_SESSION['country']);\n\t\t\tunset($_SESSION['phone']);\n\t\t\tunset($_SESSION['fax']);\n\t\t\tunset($_SESSION['email']);\n\t\t\tunset($_SESSION['nachricht']);\n\t\t\t}\n\n\t} else {\n\techo '<p class=titles>Error</p>';\n\techo '<p>Please fill in all the $fehler field. <a href=\"contact.php\">back</a></p>';\n\t}\n\techo '</div>';\n\n\t// Session unset\n\tunset($_SESSION['CAPTCHA_RndText']);\n\n?>"]
121+
]
122+
123+
----------------------------------------------------
124+
125+
Checks for issue #2156.

0 commit comments

Comments
 (0)