Fix ref counting bug in BIFs that call internal_type. (fixes #740)

This commit is contained in:
Jon Siwek 2012-01-10 12:25:33 -06:00
parent f921a4d5db
commit 2348d794b6
4 changed files with 17 additions and 7 deletions

View file

@ -16,7 +16,9 @@ RecordType* pcap_packet;
RecordType* signature_state; RecordType* signature_state;
EnumType* transport_proto; EnumType* transport_proto;
TableType* string_set; TableType* string_set;
TableType* string_array;
TableType* count_set; TableType* count_set;
VectorType* string_vec;
int watchdog_interval; int watchdog_interval;
@ -328,6 +330,8 @@ void init_net_var()
pcap_packet = internal_type("pcap_packet")->AsRecordType(); pcap_packet = internal_type("pcap_packet")->AsRecordType();
transport_proto = internal_type("transport_proto")->AsEnumType(); transport_proto = internal_type("transport_proto")->AsEnumType();
string_set = internal_type("string_set")->AsTableType(); string_set = internal_type("string_set")->AsTableType();
string_array = internal_type("string_array")->AsTableType();
string_vec = internal_type("string_vec")->AsVectorType();
ignore_checksums = opt_internal_int("ignore_checksums"); ignore_checksums = opt_internal_int("ignore_checksums");
partial_connection_ok = opt_internal_int("partial_connection_ok"); partial_connection_ok = opt_internal_int("partial_connection_ok");

View file

@ -19,7 +19,9 @@ extern RecordType* SYN_packet;
extern RecordType* pcap_packet; extern RecordType* pcap_packet;
extern EnumType* transport_proto; extern EnumType* transport_proto;
extern TableType* string_set; extern TableType* string_set;
extern TableType* string_array;
extern TableType* count_set; extern TableType* count_set;
extern VectorType* string_vec;
extern int watchdog_interval; extern int watchdog_interval;

View file

@ -363,19 +363,23 @@ function cat%(...%): string
function record_type_to_vector%(rt: string%): string_vec function record_type_to_vector%(rt: string%): string_vec
%{ %{
VectorVal* result = VectorVal* result = new VectorVal(string_vec);
new VectorVal(internal_type("string_vec")->AsVectorType());
RecordType *type = internal_type(rt->CheckString())->AsRecordType(); ID* id = lookup_ID(rt->CheckString(), GLOBAL_MODULE_NAME);
if ( type ) if ( id )
{ {
RecordType *type = id->Type()->AsRecordType();
for ( int i = 0; i < type->NumFields(); ++i ) for ( int i = 0; i < type->NumFields(); ++i )
{ {
StringVal* val = new StringVal(type->FieldName(i)); StringVal* val = new StringVal(type->FieldName(i));
result->Assign(i+1, val, 0); result->Assign(i+1, val, 0);
} }
Unref(id);
} }
else
reporter->InternalError("internal record type %s missing",
rt->CheckString());
return result; return result;
%} %}

View file

@ -129,7 +129,7 @@ function sort_string_array%(a: string_array%): string_array
} }
// sort(vs.begin(), vs.end(), Bstr_cmp); // sort(vs.begin(), vs.end(), Bstr_cmp);
TableVal* b = new TableVal(internal_type("string_array")->AsTableType()); TableVal* b = new TableVal(string_array);
vs_to_string_array(vs, b, 1, n); vs_to_string_array(vs, b, 1, n);
return b; return b;
%} %}
@ -216,7 +216,7 @@ static int match_prefix(int s_len, const char* s, int t_len, const char* t)
Val* do_split(StringVal* str_val, RE_Matcher* re, TableVal* other_sep, Val* do_split(StringVal* str_val, RE_Matcher* re, TableVal* other_sep,
int incl_sep, int max_num_sep) int incl_sep, int max_num_sep)
{ {
TableVal* a = new TableVal(internal_type("string_array")->AsTableType()); TableVal* a = new TableVal(string_array);
ListVal* other_strings = 0; ListVal* other_strings = 0;
if ( other_sep && other_sep->Size() > 0 ) if ( other_sep && other_sep->Size() > 0 )
@ -679,7 +679,7 @@ function str_shell_escape%(source: string%): string
# empty set if none). # empty set if none).
function find_all%(str: string, re: pattern%) : string_set function find_all%(str: string, re: pattern%) : string_set
%{ %{
TableVal* a = new TableVal(internal_type("string_set")->AsTableType()); TableVal* a = new TableVal(string_set);
const u_char* s = str->Bytes(); const u_char* s = str->Bytes();
const u_char* e = s + str->Len(); const u_char* e = s + str->Len();