|
|
583230 |
From 99ee8b19901f4908e2a2942731c34e03aadd9549 Mon Sep 17 00:00:00 2001
|
|
|
583230 |
From: Serhei Makarov <smakarov@redhat.com>
|
|
|
583230 |
Date: Tue, 30 Oct 2018 17:10:53 -0400
|
|
|
583230 |
Subject: [PATCH 13/32] bpf-translate.cxx :: fix segfault with malformed
|
|
|
583230 |
register
|
|
|
583230 |
|
|
|
583230 |
---
|
|
|
583230 |
bpf-translate.cxx | 9 +++++++--
|
|
|
583230 |
testsuite/systemtap.bpf/asm_tests/err-regparse.stp | 9 +++++++++
|
|
|
583230 |
2 files changed, 16 insertions(+), 2 deletions(-)
|
|
|
583230 |
create mode 100644 testsuite/systemtap.bpf/asm_tests/err-regparse.stp
|
|
|
583230 |
|
|
|
583230 |
diff --git a/bpf-translate.cxx b/bpf-translate.cxx
|
|
|
583230 |
index bb133bae5..d46dae44a 100644
|
|
|
583230 |
--- a/bpf-translate.cxx
|
|
|
583230 |
+++ b/bpf-translate.cxx
|
|
|
583230 |
@@ -952,8 +952,13 @@ bpf_unparser::emit_asm_arg (const asm_stmt &stmt, const std::string &arg,
|
|
|
583230 |
{
|
|
|
583230 |
/* arg is a register number */
|
|
|
583230 |
std::string reg = arg[0] == 'r' ? arg.substr(1) : arg;
|
|
|
583230 |
- unsigned long num = stoul(reg, 0, 0);
|
|
|
583230 |
- if (num > 10)
|
|
|
583230 |
+ unsigned long num;
|
|
|
583230 |
+ bool parsed = false;
|
|
|
583230 |
+ try {
|
|
|
583230 |
+ num = stoul(reg, 0, 0);
|
|
|
583230 |
+ parsed = true;
|
|
|
583230 |
+ } catch (std::exception &e) {} // XXX: invalid_argument, out_of_range
|
|
|
583230 |
+ if (!parsed || num > 10)
|
|
|
583230 |
throw SEMANTIC_ERROR (_F("invalid bpf register '%s'",
|
|
|
583230 |
arg.c_str()), stmt.tok);
|
|
|
583230 |
return this_prog.lookup_reg(num);
|
|
|
583230 |
diff --git a/testsuite/systemtap.bpf/asm_tests/err-regparse.stp b/testsuite/systemtap.bpf/asm_tests/err-regparse.stp
|
|
|
583230 |
new file mode 100644
|
|
|
583230 |
index 000000000..ba66800e6
|
|
|
583230 |
--- /dev/null
|
|
|
583230 |
+++ b/testsuite/systemtap.bpf/asm_tests/err-regparse.stp
|
|
|
583230 |
@@ -0,0 +1,9 @@
|
|
|
583230 |
+function foo:long () %{ /* bpf */ /* pure */
|
|
|
583230 |
+ 0xb7, $rc, -, -, 50; /* mov $rc, 50 */
|
|
|
583230 |
+ 0xbf, $$, rc, -, -; /* mov $$, $rc -- TYPO */
|
|
|
583230 |
+%}
|
|
|
583230 |
+
|
|
|
583230 |
+probe begin {
|
|
|
583230 |
+ printf("foo()=%d should be fifty\n", foo())
|
|
|
583230 |
+ exit()
|
|
|
583230 |
+}
|
|
|
583230 |
--
|
|
|
583230 |
2.14.5
|
|
|
583230 |
|