From b71d20af819bdb862ee6c8a739971db0c98dbeed Mon Sep 17 00:00:00 2001 From: Serhei Makarov Date: Mon, 14 Dec 2020 12:39:51 -0500 Subject: [PATCH] stapbpf (for PR27030): bugfix error messages in bpf assembly Need to retain the asm_stmts vector so that bpf assembly tokens are not deallocated on exception throw. Otherwise, printing semantic errors from bpf assembly causes segfault. * bpf-translate.cxx (struct bpf_unparser): retain asm_stmts vector. (bpf_unparser::visit_embeddedcode): reuse retained asm_stmts vector. --- bpf-translate.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bpf-translate.cxx b/bpf-translate.cxx index f61a088a0..b463cc818 100644 --- a/bpf-translate.cxx +++ b/bpf-translate.cxx @@ -173,6 +173,7 @@ struct bpf_unparser : public throwing_visitor // Used to track errors. value *error_status; + std::vector asm_stmts; // Used to switch execution of program to catch blocks. std::vector catch_jump; @@ -1477,7 +1478,9 @@ bpf_unparser::visit_embeddedcode (embeddedcode *s) #ifdef DEBUG_CODEGEN this_ins.notes.push("asm"); #endif - std::vector statements; + // XXX retain asm_stmts to avoid deallocating tok on throw + std::vector &statements = this->asm_stmts; + statements.clear(); asm_stmt stmt; // PR24528: The /* userspace */ annotation is used to mark -- 2.43.5