Skip to content

Commit

Permalink
Add stacktraces to dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Jan 2, 2021
1 parent c4dac99 commit 0245273
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 30 deletions.
16 changes: 16 additions & 0 deletions src/sp_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ int sp_log_request(const zend_string* restrict folder,
fprintf(file, "RULE: sp%s%s\n", from, ZSTR_VAL(text_repr));

fprintf(file, "FILE: %s:%d\n", current_filename, current_line);


zend_execute_data *orig_execute_data = EG(current_execute_data);
zend_execute_data *current = EG(current_execute_data);
while (current) {
EG(current_execute_data) = current;
char* const complete_path_function = get_complete_function_path(current);
if (complete_path_function) {
const int current_line = zend_get_executed_lineno(TSRMLS_C);
fprintf(file, "STACKTRACE: %s:%d\n", complete_path_function, current_line);
}
current = current->prev_execute_data;
}
EG(current_execute_data) = orig_execute_data;


for (size_t i = 0; zones[i].str; i++) {
zval* variable_value;
zend_string* variable_key;
Expand Down
1 change: 1 addition & 0 deletions src/tests/dump_request/config/dump_request.ini
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sp.disable_function.function("system").drop().dump("/tmp/dump_result/").simulation();
sp.disable_function.function("a").drop().dump("/tmp/dump_result/").simulation();
12 changes: 6 additions & 6 deletions src/tests/dump_request/dump_eval_blacklist.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ eval('$a = strtoupper("1234");');
echo "After eval: $a\n";
$filename = glob('/tmp/dump_result/sp_dump.*')[0];
$res = file($filename);
if ($res[2] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "1\n";
} elseif ($res[3] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "2\n";
} elseif ($res[4] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "3\n";
if ($res[3] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "Invalid GET";
} elseif ($res[4] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "Invalid POST";
} elseif ($res[5] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "Invalid COOKIE";
}
?>
--EXPECTF--
Expand Down
12 changes: 6 additions & 6 deletions src/tests/dump_request/dump_eval_whitelist.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ eval('$a = my_other_fun("1234");');
echo "After eval: $a\n";
$filename = glob('/tmp/dump_result/sp_dump.*')[0];
$res = file($filename);
if ($res[2] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "1\n";
} elseif ($res[3] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "2\n";
} elseif ($res[4] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "3\n";
if ($res[3] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "Invalid GETn";
} elseif ($res[4] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "Invalid POST\n";
} elseif ($res[5] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "Invalid COOKIE\n";
}

?>
Expand Down
12 changes: 6 additions & 6 deletions src/tests/dump_request/dump_request.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ echo "1\n";
system("echo 1337;");
$filename = glob('/tmp/dump_result/sp_dump.*')[0];
$res = file($filename);
if ($res[2] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "1\n";
} elseif ($res[3] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "2\n";
} elseif ($res[4] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "3\n";
if ($res[3] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "Invalid GET";
} elseif ($res[4] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "Invalid POST";
} elseif ($res[5] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "Invalid COOKIE";
}
?>
--EXPECTF--
Expand Down
58 changes: 58 additions & 0 deletions src/tests/dump_request/dump_request_stacktrace.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
Dump request
--SKIPIF--
<?php
if (!extension_loaded("snuffleupagus")) {
print "skip";
}

foreach (glob("/tmp/dump_result/sp_dump.*") as $dump) {
@unlink($dump);
}
@rmdir("/tmp/dump_result/");
?>
--POST--
post_a=data_post_a&post_b=data_post_b
--GET--
get_a=data_get_a&get_b=data_get_b
--COOKIE--
cookie_a=data_cookie_a&cookie_b=data_cookie_b
--INI--
sp.configuration_file={PWD}/config/dump_request.ini
--FILE--
<?php
@mkdir("/tmp/dump_result/");
foreach (glob("/tmp/dump_result/sp_dump.*") as $dump) {
@unlink($dump);
}
echo "1\n";
function a(){ echo "a"; }
function b(){ a(); }
function c(){ b(); }
function d(){ c(); }
d();

$filename = glob('/tmp/dump_result/sp_dump.*')[0];
$res = file($filename);
//var_dump($res) . "\n";
if ($res[2] != "STACKTRACE: a:7\n") {
echo "Invalid STACKTRACE for a";
} elseif ($res[3] != "STACKTRACE: b:8\n") {
echo "Invalid STACKTRACE for b";
} elseif ($res[4] != "STACKTRACE: c:9\n") {
echo "Invalid STACKTRACE for c";
} elseif ($res[5] != "STACKTRACE: d:10\n") {
echo "Invalid STACKTRACE for d";
} elseif ($res[6] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "Invalid GET";
} elseif ($res[7] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "Invalid POST";
} elseif ($res[8] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "Invalid COOKIE";
}
?>
--EXPECTF--
1

Warning: [snuffleupagus][0.0.0.0][disabled_function][simulation] Aborted execution on call of the function 'a' in %a/dump_request_stacktrace.php on line 7
a
12 changes: 6 additions & 6 deletions src/tests/dump_request/dump_request_too_big.phpt

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/tests/unserialize/dump_unserialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ echo "1\n";
var_dump(unserialize('s:1:"a";alyualskdufyhalkdjsfhalkjdhflaksjdfhlkasdhflkahdawkuerylksjdfhlkssjgdflaksjdhflkasjdf'));
$filename = glob('/tmp/dump_result/sp_dump.*')[0];
$res = file($filename);
if ($res[2] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "1\n";
} elseif ($res[3] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "2\n";
} elseif ($res[4] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "3\n";
if ($res[3] != "GET:get_a='data_get_a' get_b='data_get_b' \n") {
echo "Invalid GET\n";
} elseif ($res[4] != "POST:post_a='data_post_a' post_b='data_post_b' \n") {
echo "Invalid POST\n";
} elseif ($res[5] != "COOKIE:cookie_a='data_cookie_a&cookie_b=data_cookie_b' \n") {
echo "Invalid COOKIE\n";
}
?>
--EXPECTF--
Expand Down

0 comments on commit 0245273

Please sign in to comment.