{"action":"opened","issue":{"url":"https://api.github.com/repos/jsiwek/test/issues/31","repository_url":"https://api.github.com/repos/jsiwek/test","labels_url":"https://api.github.com/repos/jsiwek/test/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/jsiwek/test/issues/31/comments","events_url":"https://api.github.com/repos/jsiwek/test/issues/31/events","html_url":"https://github.com/jsiwek/test/issues/31","id":360077946,"node_id":"MDU6SXNzdWUzNjAwNzc5NDY=","number":31,"title":"Bro crash with packet filter definition","user":{"login":"jsiwek","id":422685,"node_id":"MDQ6VXNlcjQyMjY4NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/422685?v=4","gravatar_id":"","url":"https://api.github.com/users/jsiwek","html_url":"https://github.com/jsiwek","followers_url":"https://api.github.com/users/jsiwek/followers","following_url":"https://api.github.com/users/jsiwek/following{/other_user}","gists_url":"https://api.github.com/users/jsiwek/gists{/gist_id}","starred_url":"https://api.github.com/users/jsiwek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsiwek/subscriptions","organizations_url":"https://api.github.com/users/jsiwek/orgs","repos_url":"https://api.github.com/users/jsiwek/repos","events_url":"https://api.github.com/users/jsiwek/events{/privacy}","received_events_url":"https://api.github.com/users/jsiwek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-13T21:45:16Z","updated_at":"2018-09-13T21:45:16Z","closed_at":null,"author_association":"OWNER","body":"Moved from https://bro-tracker.atlassian.net/browse/BIT-1640\n\nCreated by Johanna Amann at 2016-07-03T09:35:49.480-0500:\n> Reported via email; crash with:\r\n> \r\n> ```\r\n> @load base/frameworks/packet-filter\r\n> redef PacketFilter::restricted_filter = PacketFilter::port_to_bpf(80/tcp);\r\n> ```\r\n> \r\n> backtrace:\r\n> ```\r\n> * thread #1: tid = 0x1f713, 0x000000010001aa60 bro`Ref(o=0x0000000000000000) + 16 at Obj.h:210, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1c)\r\n>     frame #0: 0x000000010001aa60 bro`Ref(o=0x0000000000000000) + 16 at Obj.h:210\r\n>    207 \t\r\n>    208 \tinline void Ref(BroObj* o)\r\n>    209 \t\t{\r\n> -> 210 \t\tif ( ++o->ref_cnt <= 1 )\r\n>    211 \t\t\tbad_ref(0);\r\n>    212 \t\tif ( o->ref_cnt == INT_MAX )\r\n>    213 \t\t\tbad_ref(1);\r\n> (lldb) bt\r\n> * thread #1: tid = 0x1f713, 0x000000010001aa60 bro`Ref(o=0x0000000000000000) + 16 at Obj.h:210, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1c)\r\n>   * frame #0: 0x000000010001aa60 bro`Ref(o=0x0000000000000000) + 16 at Obj.h:210\r\n>     frame #1: 0x000000010001b31f bro`BroType::Ref(this=0x0000000000000000) + 31 at Type.h:250\r\n>     frame #2: 0x000000010001b2b9 bro`Val::Val(this=0x00000001061c80f0, t=0x0000000000000000) + 73 at Val.h:377\r\n>     frame #3: 0x000000010001b213 bro`EnumVal::EnumVal(this=0x00000001061c80f0, i=1, t=0x0000000000000000) + 35 at Val.h:955\r\n>     frame #4: 0x000000010001a983 bro`EnumVal::EnumVal(this=0x00000001061c80f0, i=1, t=0x0000000000000000) + 35 at Val.h:956\r\n>     frame #5: 0x0000000100112981 bro`map_conn_type(tp=TRANSPORT_TCP) + 193 at bro.bif:3120\r\n>     frame #6: 0x0000000100112c41 bro`BifFunc::bro_get_port_transport_proto(frame=0x00000001061c8020, BiF_ARGS=0x00000001061c8090) + 113 at bro.bif:3171\r\n>     frame #7: 0x000000010010565f bro`BuiltinFunc::Call(this=0x0000000102b68d60, args=0x00000001061c8090, parent=0x00000001061c8020) const + 1183 at Func.cc:586\r\n>     frame #8: 0x00000001000f2e75 bro`CallExpr::Eval(this=0x0000000102e181e0, f=0x00000001061c8020) const + 421 at Expr.cc:4544\r\n>     frame #9: 0x00000001000e5a7d bro`AssignExpr::Eval(this=0x0000000102e18380, f=0x00000001061c8020) const + 93 at Expr.cc:2400\r\n>     frame #10: 0x00000001001fae44 bro`ExprStmt::Exec(this=0x0000000102e18500, f=0x00000001061c8020, flow=0x00007fff5fbf48b0) const + 84 at Stmt.cc:352\r\n>     frame #11: 0x000000010020245b bro`StmtList::Exec(this=0x0000000102e17c20, f=0x00000001061c8020, flow=0x00007fff5fbf48b0) const + 219 at Stmt.cc:1699\r\n>     frame #12: 0x0000000100103b2b bro`BroFunc::Call(this=0x0000000102e18fc0, args=0x00000001061c79e0, parent=0x0000000000000000) const + 3179 at Func.cc:403\r\n>     frame #13: 0x00000001000f2e75 bro`CallExpr::Eval(this=0x00000001061c7f10, f=0x0000000000000000) const + 421 at Expr.cc:4544\r\n>     frame #14: 0x00000001000d6f8a bro`Expr::InitVal(this=0x00000001061c7f10, t=0x0000000101f8af30, aggr=0x0000000000000000) const + 122 at Expr.cc:130\r\n>     frame #15: 0x000000010023ab25 bro`init_val(init=0x00000001061c7f10, t=0x0000000101f8af30, aggr=0x0000000000000000) + 69 at Var.cc:16\r\n>     frame #16: 0x000000010023876f bro`make_var(id=0x00000001051b1d10, t=0x0000000101f8af30, c=INIT_FULL, init=0x00000001061c7f10, attr=0x0000000000000000, dt=VAR_REDEF, do_init=1) + 2223 at Var.cc:190\r\n>     frame #17: 0x0000000100237eba bro`add_global(id=0x00000001051b1d10, t=0x0000000000000000, c=INIT_FULL, init=0x00000001061c7f10, attr=0x0000000000000000, dt=VAR_REDEF) + 74 at Var.cc:228\r\n>     frame #18: 0x0000000100013159 bro`yyparse() + 29161 at parse.y:1070\r\n>     frame #19: 0x000000010003b750 bro`main(argc=4, argv=0x00007fff5fbff670) + 11776 at main.cc:892\r\n>     frame #20: 0x00007fff93c695ad libdyld.dylib`start + 1\r\n> ```\n\nComment by Johanna Amann at 2016-07-05T13:31:13.305-0500:\n> Ok, I figured out what is going on here. The problem is that get_port_transport_proto (called in PacketFilter::port_to_bpf) indirectly calls:\r\n\r\n```\r\nreturn new EnumVal(1, transport_proto);\r\n```\r\n\r\ntransport_proto is one of the variables that is populated in init_net_var (NetVar.cc). This happens only after yyparse() is done. init_net_var cannot be moved before yyparse, because it needs the types that are generated during parsing.\r\n\r\nAnd with that I am a bit unsure what we should do here - basically, using functions in redefs will work in many cases, but will cause a crash anytime one of the netvars is used internally. I don't really think we use this ourselves - would it perhaps make sense to just prohibit function calls in redefs?\n\nComment by Johanna Amann at 2016-07-05T15:05:37.624-0500:\n> I just talked to Robin for a few minutes - a possible solution to this problem would be to split parsing into two steps - parse init_bare first, which populates the records, then call init_net_var, then parse the rest. I will try to look if this is possible...\n\n"}}
{"actor":{"display_login":"jsiwek"}}