aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-09-21 10:23:16 -0700
committerYonghong Song <yhs@fb.com>2018-09-21 10:23:16 -0700
commita6d7e3af1fd342adf9f62e5246c74e4a3e02106c (patch)
treea2a6ef1a14f4cd32ce5f4e814db9612d91dc1014 /src
parentc7ccd5b701959013d6565c8b6b5fbfe20ba46567 (diff)
downloadbcc-a6d7e3af1fd342adf9f62e5246c74e4a3e02106c.tar.gz
prevent array subscript expression if base/index is not rewritable
The following command failed: trace.py -U 'r::_do_fork (retval == -11) "%llu", ((struct task_struct *)bpf_get_current_task())->signal->rlim[RLIMIT_NPROC].rlim_cur' as rewriter generates code like __data.v0 = (unsigned long long)((struct task_struct *)bpf_get_current_task())->signal->rlim[RLIMIT_NPROC))); _val; }).rlim_cur; Let us prevent rewriting if either base or index is not rewritable and this fixed the issue. Signed-off-by: Yonghong Song <yhs@fb.com>
Diffstat (limited to 'src')
-rw-r--r--src/cc/frontends/clang/b_frontend_action.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
index dada311e..59ce9fac 100644
--- a/src/cc/frontends/clang/b_frontend_action.cc
+++ b/src/cc/frontends/clang/b_frontend_action.cc
@@ -505,6 +505,12 @@ bool ProbeVisitor::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Expr *idx = E->getIdx();
memb_visited_.insert(E);
+ if (!rewriter_.isRewritable(GET_BEGINLOC(base)))
+ return true;
+ if (!rewriter_.isRewritable(GET_BEGINLOC(idx)))
+ return true;
+
+
string pre, lbracket, rbracket;
LangOptions opts;
SourceLocation lbracket_start, lbracket_end;