Skip to content

Commit

Permalink
Merge pull request iovisor#1005 from pchaigno/rewrite-only-deref
Browse files Browse the repository at this point in the history
Restrict rewrite of unary operators to dereference operator
  • Loading branch information
drzaeus77 authored Mar 7, 2017
2 parents d05e66d + 4c6ecb4 commit 575b3e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool ProbeVisitor::VisitBinaryOperator(BinaryOperator *E) {
return true;
}
bool ProbeVisitor::VisitUnaryOperator(UnaryOperator *E) {
if (E->getOpcode() == UO_AddrOf)
if (E->getOpcode() != UO_Deref)
return true;
if (memb_visited_.find(E) != memb_visited_.end())
return true;
Expand Down
11 changes: 11 additions & 0 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ def test_bpf_dins_pkt_rewrite(self):
"""
b = BPF(text=text)

def test_unary_operator(self):
text = """
#include <linux/fs.h>
#include <uapi/linux/ptrace.h>
int trace_read_entry(struct pt_regs *ctx, struct file *file) {
return !file->f_op->read_iter;
}
"""
b = BPF(text=text)
b.attach_kprobe(event="__vfs_read", fn_name="trace_read_entry")

if __name__ == "__main__":
main()

Expand Down

0 comments on commit 575b3e5

Please sign in to comment.