-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix segfault for invalid AssignVarStatement visit #2423
Fix segfault for invalid AssignVarStatement visit #2423
Conversation
44778fd
to
51726ca
Compare
I'd say that the actual problem is that typecast gets an invalid expression (one with |
@viktormalik You are right, thanks a lot, i just update this PR. $ cat sample.bt #include <linux/fs.h>
kprobe:vfs_open {
$file = (struct file *)
printf("Hello\n");
}
|
51726ca
to
a49eccb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, can you update the CHANGELOG, too?
Nit: the change now fixes an invalid typecast rather than variable assignment. Perhaps the commit message (and the CHANGELOG entry) could reflect that.
a49eccb
to
6a293be
Compare
The change now fixes an invalid typecast rather than variable assignment. When CodegenLLVM::visit calls CreateStore() with NULL expr_ as parameter, segfault is generated, for example: $ cat sample.bt #include <linux/fs.h> kprobe:vfs_open { $file = (struct file *) printf("Hello\n"); } Acctually, we want to '$file = (struct file *)arg1;' here. When writing incorrectly '$file = (struct file *)', printf() make expr_ == nullptr, when call CreateStore(NULL, ...), segfault has occurred, and the stack backtrace is as follows: (gdb) bt #0 0x00000000007098c6 in llvm::Value::getType (this=0x0) at /usr/include/llvm/IR/Value.h:255 bpftrace#1 0x000000000070cc76 in llvm::IRBuilderBase::CreateAlignedStore (this=0x7fffffffbe40, Val=0x0, Ptr=0x15e2340, Align=..., isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1689 bpftrace#2 0x000000000070cab3 in llvm::IRBuilderBase::CreateStore (this=0x7fffffffbe40, Val=0x0, Ptr=0x15e2340, isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1663 bpftrace#3 0x00000000006f6948 in bpftrace::ast::CodegenLLVM::visit (this=0x7fffffffbe10, assignment=...) at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2140 bpftrace#4 0x0000000000751258 in bpftrace::ast::AssignVarStatement::accept (this=0x7fffe99b9a30, v=...) at /home/rongtao/Git/bpftrace/src/ast/ast.cpp:35 bpftrace#5 0x00000000006ff6ea in bpftrace::ast::CodegenLLVM::accept (this=0x7fffffffbe10, node=0x7fffe99b9a30) at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3360 We should prompt the user for some useful information, like: $ sudo ./sample.bt ./sample.bt:4:11-26: ERROR: Cannot cast from "none" type $file = (struct file *) ~~~~~~~~~~~~~~~ LLVM/Clang Version: 15.0.1 Signed-off-by: Rong Tao <[email protected]>
6a293be
to
e223ef0
Compare
Done to update the CHANGELOG, thanks. |
When CodegenLLVM::visit calls CreateStore() with NULL expr_ as parameter, segfault is generated, for example:
Acctually, we want to '
$file = (struct file *)arg1;
' here. When writing incorrectly '$file = (struct file *)
', printf() makeexpr_ == nullptr
, when call CreateStore(NULL, ...), segfault has occurred, and the stack backtrace is as follows:We should prompt the user for some useful information, like:
We can't solve this problem semantic_analyser because the syntax is correct. Maybe in the future we can solve it by modifying parser.yy, but this modification is not considered because it is more complicated. In any case, the CreateStore() parameter should not be NULL during the codegen phase.
LLVM/Clang Version: 15.0.1