mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Skip input framework entries with missing but non-optional fields
The framework so far populated data structures with missing fields even when those fields are defined without the &optional attribute. When using the attribute, such entries continue to get populated. Update tests to reflect focus on unset fields.
This commit is contained in:
parent
ef08605877
commit
937bdccab5
9 changed files with 122 additions and 59 deletions
|
@ -1935,6 +1935,12 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v
|
|||
// Better check that it really is optional. Uou never know.
|
||||
assert(request_type->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL));
|
||||
}
|
||||
else if ( ! vals[*position]->present &&
|
||||
! request_type->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) )
|
||||
{
|
||||
Warning(stream, "Skipping input with missing non-optional value");
|
||||
have_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldVal = ValueToVal(stream, vals[*position], request_type->GetFieldType(i).get(), have_error);
|
||||
|
|
|
@ -5,49 +5,55 @@ Description
|
|||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 1], [s=<uninitialized>, ss=TEST]
|
||||
destination[left = 3], [s=TEST, ss=<uninitialized>]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_NEW
|
||||
Left, [i=3]
|
||||
Right, [s=TEST, ss=<uninitialized>]
|
||||
============EVENT============
|
||||
Description
|
||||
source, ../input.log
|
||||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 4], [s=TEST, ss=TEST]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_NEW
|
||||
Left, [i=4]
|
||||
Right, [s=TEST, ss=TEST]
|
||||
============EVENT============
|
||||
Description
|
||||
source, ../input.log
|
||||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 1], [s=TEST2, ss=<uninitialized>]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_NEW
|
||||
Left, [i=1]
|
||||
Right, [s=<uninitialized>, ss=TEST]
|
||||
Right, [s=TEST2, ss=<uninitialized>]
|
||||
============EVENT============
|
||||
Description
|
||||
source, ../input.log
|
||||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 2], [s=<uninitialized>, ss=<uninitialized>]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_NEW
|
||||
Left, [i=2]
|
||||
Right, [s=<uninitialized>, ss=<uninitialized>]
|
||||
============EVENT============
|
||||
Description
|
||||
source, ../input.log
|
||||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 1], [s=TEST, ss=<uninitialized>]
|
||||
destination[left = 4], [s=TEST2, ss=TEST2]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_CHANGED
|
||||
Left, [i=1]
|
||||
Right, [s=<uninitialized>, ss=TEST]
|
||||
Left, [i=4]
|
||||
Right, [s=TEST, ss=TEST]
|
||||
============EVENT============
|
||||
Description
|
||||
source, ../input.log
|
||||
reader, Input::READER_ASCII
|
||||
mode, Input::REREAD
|
||||
name, ssh
|
||||
destination[left = 2], [s=TEST, ss=TEST]
|
||||
idx, A::Idx
|
||||
val, A::Val
|
||||
want_record, T
|
||||
Type, Input::EVENT_CHANGED
|
||||
Left, [i=2]
|
||||
Right, [s=<uninitialized>, ss=<uninitialized>]
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
============PREDICATE============
|
||||
Input::EVENT_NEW
|
||||
[i=1]
|
||||
[s=<uninitialized>, ss=TEST]
|
||||
============PREDICATE============
|
||||
Input::EVENT_NEW
|
||||
[i=2]
|
||||
[s=<uninitialized>, ss=<uninitialized>]
|
||||
============PREDICATE============
|
||||
Input::EVENT_CHANGED
|
||||
[i=1]
|
||||
[i=3]
|
||||
[s=TEST, ss=<uninitialized>]
|
||||
============PREDICATE============
|
||||
Input::EVENT_CHANGED
|
||||
[i=2]
|
||||
Input::EVENT_NEW
|
||||
[i=4]
|
||||
[s=TEST, ss=TEST]
|
||||
============PREDICATE============
|
||||
Input::EVENT_NEW
|
||||
[i=1]
|
||||
[s=TEST2, ss=<uninitialized>]
|
||||
============PREDICATE============
|
||||
Input::EVENT_CHANGED
|
||||
[i=4]
|
||||
[s=TEST2, ss=TEST2]
|
||||
============PREDICATE============
|
||||
Input::EVENT_REMOVED
|
||||
[i=3]
|
||||
[s=TEST, ss=<uninitialized>]
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
==========SERVERS============
|
||||
{
|
||||
[2] = [s=<uninitialized>, ss=<uninitialized>],
|
||||
[1] = [s=<uninitialized>, ss=TEST]
|
||||
[4] = [s=TEST, ss=TEST],
|
||||
[3] = [s=TEST, ss=<uninitialized>]
|
||||
}
|
||||
==========SERVERS============
|
||||
{
|
||||
[2] = [s=TEST, ss=TEST],
|
||||
[1] = [s=TEST, ss=<uninitialized>]
|
||||
[4] = [s=TEST2, ss=TEST2],
|
||||
[1] = [s=TEST2, ss=<uninitialized>]
|
||||
}
|
||||
done
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
{
|
||||
[2] = [b=<uninitialized>],
|
||||
[1] = [b=T]
|
||||
}
|
||||
{
|
||||
[1, 1] = [b=T],
|
||||
[2, 2] = [b=<uninitialized>]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
warning: Skipping input with missing non-optional value
|
||||
warning: ..<...>/Input::READER_ASCII: Invalid value for subnet: 127.0.0.1
|
||||
warning: ..<...>/Input::READER_ASCII: Error while reading set or vector
|
||||
warning: ..<...>/Input::READER_ASCII: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line.
|
||||
warning: Skipping input with missing non-optional value
|
||||
warning: ..<...>/Input::READER_ASCII: Invalid value for subnet: 127.0.0.1
|
||||
warning: ..<...>/Input::READER_ASCII: Error while reading set or vector
|
||||
warning: ..<...>/Input::READER_ASCII: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line.
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
### NOTE: This file has been sorted with diff-sort.
|
||||
|
||||
|
||||
Event, [s={
|
||||
EventErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING
|
||||
EventErrorEvent, Error while reading set or vector, Reporter::WARNING
|
||||
EventErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING
|
||||
EventErrorEvent, Skipping input with missing non-optional value, Reporter::WARNING
|
||||
TableErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING
|
||||
TableErrorEvent, Error while reading set or vector, Reporter::WARNING
|
||||
TableErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING
|
||||
[name] = [s={
|
||||
TableErrorEvent, Skipping input with missing non-optional value, Reporter::WARNING
|
||||
{
|
||||
}
|
||||
}]
|
||||
}]
|
||||
|
|
|
@ -11,15 +11,18 @@
|
|||
#separator \x09
|
||||
#fields i s ss
|
||||
#types int sting string
|
||||
1 - TEST
|
||||
2 - -
|
||||
1 - -
|
||||
2 - TEST
|
||||
3 TEST -
|
||||
4 TEST TEST
|
||||
@TEST-END-FILE
|
||||
@TEST-START-FILE input2.log
|
||||
#separator \x09
|
||||
#fields i s ss
|
||||
#types int sting string
|
||||
1 TEST -
|
||||
2 TEST TEST
|
||||
1 TEST2 -
|
||||
4 TEST2 TEST2
|
||||
5 - TEST2
|
||||
@TEST-END-FILE
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
@ -32,7 +35,7 @@ type Idx: record {
|
|||
|
||||
type Val: record {
|
||||
s: string;
|
||||
ss: string;
|
||||
ss: string &optional;
|
||||
};
|
||||
|
||||
type servers_type: table[int] of Val;
|
||||
|
|
|
@ -1,14 +1,31 @@
|
|||
# This test verifies the handling of unset fields in input files.
|
||||
# For table indexes, columns wwith undefined fields cannot work
|
||||
# and are skipped. For values, unset fields are safe for the user
|
||||
# only when those fields are defined &optional, otherwise they
|
||||
# too are skipped.
|
||||
|
||||
# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 10
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
@TEST-START-FILE input.log
|
||||
@TEST-START-FILE input1.log
|
||||
#separator \x09
|
||||
#path ssh
|
||||
#fields b i
|
||||
##types bool int
|
||||
T 1
|
||||
- 2
|
||||
F -
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE input2.log
|
||||
#separator \x09
|
||||
#path ssh
|
||||
#fields b i j
|
||||
##types bool int int
|
||||
T 1 1
|
||||
- 2 2
|
||||
F - 3
|
||||
@TEST-END-FILE
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
@ -19,27 +36,52 @@ redef InputAscii::empty_field = "EMPTY";
|
|||
|
||||
module A;
|
||||
|
||||
type Idx: record {
|
||||
# We use two different index records just because the internal code
|
||||
# paths differ slightly for these. And one used to crash. :)
|
||||
type Idx1: record {
|
||||
i: int;
|
||||
};
|
||||
|
||||
type Val: record {
|
||||
type Idx2: record {
|
||||
i: int;
|
||||
j: int;
|
||||
};
|
||||
|
||||
type ValReq: record {
|
||||
b: bool;
|
||||
};
|
||||
|
||||
global servers: table[int] of Val = table();
|
||||
type ValOpt: record {
|
||||
b: bool &optional;
|
||||
};
|
||||
|
||||
global servers1: table[int] of ValReq = table();
|
||||
global servers2: table[int, int] of ValOpt = table();
|
||||
|
||||
# Counter to track when we're ready to report both table's contents in
|
||||
# pre-defined order.
|
||||
global reads_done = 0;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
outfile = open("../out");
|
||||
outfile = open("../out");
|
||||
# first read in the old stuff into the table...
|
||||
Input::add_table([$source="../input.log", $name="ssh", $idx=Idx, $val=Val, $destination=servers]);
|
||||
Input::add_table([$source="../input1.log", $name="ssh1", $idx=Idx1, $val=ValReq, $destination=servers1]);
|
||||
Input::add_table([$source="../input2.log", $name="ssh2", $idx=Idx2, $val=ValOpt, $destination=servers2]);
|
||||
}
|
||||
|
||||
event Input::end_of_data(name: string, source:string)
|
||||
{
|
||||
print outfile, servers;
|
||||
Input::remove("ssh");
|
||||
reads_done += 1;
|
||||
if ( reads_done < 2 )
|
||||
return;
|
||||
|
||||
print outfile, servers1;
|
||||
print outfile, servers2;
|
||||
|
||||
Input::remove("ssh1");
|
||||
Input::remove("ssh2");
|
||||
|
||||
close(outfile);
|
||||
terminate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue