Skip to content

Commit

Permalink
Fix crash when using $0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajor committed Jul 9, 2019
1 parent e98530c commit b41d66d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ast/semantic_analyser.cpp
Expand Up @@ -22,6 +22,10 @@ void SemanticAnalyser::visit(Integer &integer)

void SemanticAnalyser::visit(PositionalParameter &param)
{
if (param.n <= 0) {
err_ << "$" << param.n << " is not a valid parameter" << std::endl;
}

param.type = SizedType(Type::integer, 8);
if (is_final_pass()) {
std::string pstr = bpftrace_.get_param(param.n, param.is_in_str);
Expand Down
4 changes: 4 additions & 0 deletions tests/semantic_analyser.cpp
Expand Up @@ -930,12 +930,16 @@ TEST(semantic_analyser, positional_parameters)
bpftrace.add_param("123");
bpftrace.add_param("hello");

test(bpftrace, "kprobe:f { printf(\"%d\", $0); }", 1);
test(bpftrace, "kprobe:f { printf(\"%s\", str($0)); }", 1);

test(bpftrace, "kprobe:f { printf(\"%d\", $1); }", 0);
test(bpftrace, "kprobe:f { printf(\"%s\", str($1)); }", 10);

test(bpftrace, "kprobe:f { printf(\"%s\", str($2)); }", 0);
test(bpftrace, "kprobe:f { printf(\"%d\", $2); }", 10);

// Parameters are not required to exist to be used:
test(bpftrace, "kprobe:f { printf(\"%s\", str($3)); }", 0);
test(bpftrace, "kprobe:f { printf(\"%d\", $3); }", 0);
}
Expand Down

0 comments on commit b41d66d

Please sign in to comment.