summaryrefslogtreecommitdiff
path: root/tests/executor
diff options
context:
space:
mode:
authorStefan Esser2010-02-21 11:44:54 +0100
committerStefan Esser2010-02-21 11:44:54 +0100
commit36dbfacbe64697d959f524e537b15b73c090d898 (patch)
treef1c7ce1409b0e7765fc72d550546967fcf0f9717 /tests/executor
Inital commit
Diffstat (limited to 'tests/executor')
-rw-r--r--tests/executor/disable_emod_off.phpt18
-rw-r--r--tests/executor/disable_emod_on.phpt19
-rw-r--r--tests/executor/disable_eval_off.phpt15
-rw-r--r--tests/executor/disable_eval_on.phpt17
-rw-r--r--tests/executor/memory_limit.phpt29
-rw-r--r--tests/executor/memory_limit_other_hardlimit.phpt28
-rw-r--r--tests/executor/negative_memory_limit.phpt18
-rw-r--r--tests/executor/preg_replace.phpt30
-rw-r--r--tests/executor/preg_replace_error.phpt32
-rw-r--r--tests/executor/recursion_maxdepth.phpt31
10 files changed, 237 insertions, 0 deletions
diff --git a/tests/executor/disable_emod_off.phpt b/tests/executor/disable_emod_off.phpt
new file mode 100644
index 0000000..3c9cb01
--- /dev/null
+++ b/tests/executor/disable_emod_off.phpt
@@ -0,0 +1,18 @@
1--TEST--
2Testing: suhosin.executor.disable_emodifier=0
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7suhosin.executor.disable_emodifier=0
8--FILE--
9<?php
10 $text = "HALLO";
11 var_dump(preg_replace('/[a-z]/e', "strtoupper('\\0')", $text));
12 $text = "HalLO";
13 var_dump(preg_replace('/[a-z]/e', "strtoupper('\\0')", $text));
14?>
15--EXPECTF--
16string(5) "HALLO"
17string(5) "HALLO"
18
diff --git a/tests/executor/disable_emod_on.phpt b/tests/executor/disable_emod_on.phpt
new file mode 100644
index 0000000..6daf82f
--- /dev/null
+++ b/tests/executor/disable_emod_on.phpt
@@ -0,0 +1,19 @@
1--TEST--
2Testing: suhosin.executor.disable_emodifier=1
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7suhosin.executor.disable_emodifier=1
8--FILE--
9<?php
10 $text = "HALLO";
11 var_dump(preg_replace('/[a-z]/e', "strtoupper('\\0')", $text));
12 $text = "HalLO";
13 var_dump(preg_replace('/[a-z]/e', "strtoupper('\\0')", $text));
14?>
15--EXPECTF--
16string(5) "HALLO"
17ALERT - use of preg_replace() with /e modifier is forbidden by configuration (attacker 'REMOTE_ADDR not set', file '%s', line 5)
18
19Fatal error: SUHOSIN - Use of preg_replace() with /e modifier is forbidden by configuration in %s(5) : regexp code on line 5
diff --git a/tests/executor/disable_eval_off.phpt b/tests/executor/disable_eval_off.phpt
new file mode 100644
index 0000000..1ee87f5
--- /dev/null
+++ b/tests/executor/disable_eval_off.phpt
@@ -0,0 +1,15 @@
1--TEST--
2Testing: suhosin.executor.disable_eval=0
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7suhosin.executor.disable_eval=0
8--FILE--
9<?php
10 $x = 0;
11 eval('$x = 1;');
12 var_dump($x);
13?>
14--EXPECTF--
15int(1)
diff --git a/tests/executor/disable_eval_on.phpt b/tests/executor/disable_eval_on.phpt
new file mode 100644
index 0000000..49f4936
--- /dev/null
+++ b/tests/executor/disable_eval_on.phpt
@@ -0,0 +1,17 @@
1--TEST--
2Testing: suhosin.executor.disable_eval=1
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7suhosin.executor.disable_eval=1
8--FILE--
9<?php
10 $x = 0;
11 eval('$x = 1;');
12 var_dump($x);
13?>
14--EXPECTF--
15ALERT - use of eval is forbidden by configuration (attacker 'REMOTE_ADDR not set', file '%s', line 3)
16
17Fatal error: SUHOSIN - Use of eval is forbidden by configuration in %s(3) : eval()'d code on line 3
diff --git a/tests/executor/memory_limit.phpt b/tests/executor/memory_limit.phpt
new file mode 100644
index 0000000..404ab19
--- /dev/null
+++ b/tests/executor/memory_limit.phpt
@@ -0,0 +1,29 @@
1--TEST--
2memory_limit test: set suhosin hard_limit to normal limit
3--SKIPIF--
4<?php if (!function_exists("memory_get_usage")) print "skip PHP not compiled with memory_limit support"; ?>
5--INI--
6memory_limit=16M
7suhosin.memory_limit=0
8suhosin.log.syslog=0
9suhosin.log.script=0
10suhosin.log.sapi=2
11--FILE--
12<?php
13 ini_set("memory_limit", "13M"); echo ini_get("memory_limit"), "\n";
14 ini_set("memory_limit", "14M"); echo ini_get("memory_limit"), "\n";
15 ini_set("memory_limit", "15M"); echo ini_get("memory_limit"), "\n";
16 ini_set("memory_limit", "16M"); echo ini_get("memory_limit"), "\n";
17 ini_set("memory_limit", "17M"); echo ini_get("memory_limit"), "\n";
18 ini_set("memory_limit", "18M"); echo ini_get("memory_limit"), "\n";
19?>
20--EXPECTF--
2113M
2214M
2315M
2416M
25ALERT - script tried to increase memory_limit to 17825792 bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '%s', line 6)
2616M
27ALERT - script tried to increase memory_limit to 18874368 bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '%s', line 7)
2816M
29
diff --git a/tests/executor/memory_limit_other_hardlimit.phpt b/tests/executor/memory_limit_other_hardlimit.phpt
new file mode 100644
index 0000000..cac11dc
--- /dev/null
+++ b/tests/executor/memory_limit_other_hardlimit.phpt
@@ -0,0 +1,28 @@
1--TEST--
2memory_limit test: set suhosin hard_limit to normal limit + 1M
3--SKIPIF--
4<?php if (!function_exists("memory_get_usage")) print "skip PHP not compiled with memory_limit support"; ?>
5--INI--
6memory_limit=16M
7suhosin.memory_limit=17M
8suhosin.log.syslog=0
9suhosin.log.script=0
10suhosin.log.sapi=2
11--FILE--
12<?php
13 ini_set("memory_limit", "13M"); echo ini_get("memory_limit"), "\n";
14 ini_set("memory_limit", "14M"); echo ini_get("memory_limit"), "\n";
15 ini_set("memory_limit", "15M"); echo ini_get("memory_limit"), "\n";
16 ini_set("memory_limit", "16M"); echo ini_get("memory_limit"), "\n";
17 ini_set("memory_limit", "17M"); echo ini_get("memory_limit"), "\n";
18 ini_set("memory_limit", "18M"); echo ini_get("memory_limit"), "\n";
19?>
20--EXPECTF--
2113M
2214M
2315M
2416M
2517M
26ALERT - script tried to increase memory_limit to %d bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '%s', line 7)
2717M
28
diff --git a/tests/executor/negative_memory_limit.phpt b/tests/executor/negative_memory_limit.phpt
new file mode 100644
index 0000000..8582cc9
--- /dev/null
+++ b/tests/executor/negative_memory_limit.phpt
@@ -0,0 +1,18 @@
1--TEST--
2memory_limit test: trying to set memory_limit to a negative value
3--SKIPIF--
4<?php if (!function_exists("memory_get_usage")) print "skip PHP not compiled with memory_limit support"; ?>
5--INI--
6memory_limit=16M
7suhosin.memory_limit=17M
8suhosin.log.syslog=0
9suhosin.log.script=0
10suhosin.log.sapi=2
11--FILE--
12<?php
13 ini_set("memory_limit", "-200000"); echo ini_get("memory_limit"), "\n";
14?>
15--EXPECTF--
16ALERT - script tried to increase memory_limit to %d bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '%s', line 2)
1716M
18
diff --git a/tests/executor/preg_replace.phpt b/tests/executor/preg_replace.phpt
new file mode 100644
index 0000000..9060a29
--- /dev/null
+++ b/tests/executor/preg_replace.phpt
@@ -0,0 +1,30 @@
1--TEST--
2Testing protection against "\0" in preg_replace() first parameter
3--SKIPIF--
4<?php include "../skipif.inc"; ?>
5--INI--
6suhosin.log.sapi=0
7--FILE--
8<?php
9
10 $text1 = "One little boy with two dogs, three cats and four birds";
11 $text2 = "The three cats eat the four birds";
12
13 $regex_array = array("/one/", "/two/", "/three/");
14 $regex_array0 = array("/one/\0", "/two/", "/three/");
15 $replace_array = array("1", "2", "3");
16 $regex = "/eat/";
17 $regex0 = "/ea\0t/";
18 $replace = "play with";
19
20 var_dump(preg_replace($regex_array, $replace_array, $text1));
21 var_dump(preg_replace($regex_array0, $replace_array, $text1));
22 var_dump(preg_replace($regex, $replace, $text2));
23 var_dump(preg_replace($regex0, $replace, $text2));
24
25?>
26--EXPECT--
27string(49) "One little boy with 2 dogs, 3 cats and four birds"
28bool(false)
29string(39) "The three cats play with the four birds"
30bool(false)
diff --git a/tests/executor/preg_replace_error.phpt b/tests/executor/preg_replace_error.phpt
new file mode 100644
index 0000000..39e0aee
--- /dev/null
+++ b/tests/executor/preg_replace_error.phpt
@@ -0,0 +1,32 @@
1--TEST--
2Testing protection against "\0" in preg_replace() first parameter (INCL. SUHOSIN ERROR MESSAGES)
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7--FILE--
8<?php
9
10 $text1 = "One little boy with two dogs, three cats and four birds";
11 $text2 = "The three cats eat the four birds";
12
13 $regex_array = array("/one/", "/two/", "/three/");
14 $regex_array0 = array("/one/\0", "/two/", "/three/");
15 $replace_array = array("1", "2", "3");
16 $regex = "/eat/";
17 $regex0 = "/ea\0t/";
18 $replace = "play with";
19
20 var_dump(preg_replace($regex_array, $replace_array, $text1));
21 var_dump(preg_replace($regex_array0, $replace_array, $text1));
22 var_dump(preg_replace($regex, $replace, $text2));
23 var_dump(preg_replace($regex0, $replace, $text2));
24
25?>
26--EXPECTF--
27string(49) "One little boy with 2 dogs, 3 cats and four birds"
28ALERT - string termination attack on first preg_replace parameter detected (attacker 'REMOTE_ADDR not set', file '%s', line 14)
29bool(false)
30string(39) "The three cats play with the four birds"
31ALERT - string termination attack on first preg_replace parameter detected (attacker 'REMOTE_ADDR not set', file '%s', line 16)
32bool(false)
diff --git a/tests/executor/recursion_maxdepth.phpt b/tests/executor/recursion_maxdepth.phpt
new file mode 100644
index 0000000..31fe9c2
--- /dev/null
+++ b/tests/executor/recursion_maxdepth.phpt
@@ -0,0 +1,31 @@
1--TEST--
2Testing: suhosin.executor.max_depth
3--SKIPIF--
4<?php include "../skipifnotcli.inc"; ?>
5--INI--
6suhosin.log.sapi=64
7suhosin.executor.max_depth=13
8--FILE--
9<?php
10 function rec($level)
11 {
12 echo $level,"\n";
13 rec(++$level);
14 }
15
16 rec(2);
17?>
18--EXPECTF--
192
203
214
225
236
247
258
269
2710
2811
2912
3013
31ALERT - maximum execution depth reached - script terminated (attacker 'REMOTE_ADDR not set', file '%s', line 5)