Avoid duplicating warnings when reading table

Invalid lines in a file was the one case that would not suppress future
warnings. Just make it suppress warnings too, but clear that suppression
if there is a field in between that doesn't error.

Fixes #3692
This commit is contained in:
Evan Typanski 2024-09-24 11:03:20 -04:00
parent 54391f50d9
commit 6e8d43a552
3 changed files with 61 additions and 5 deletions

View file

@ -6,7 +6,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <cerrno> #include <cerrno>
#include <sstream>
#include "zeek/input/readers/ascii/ascii.bif.h" #include "zeek/input/readers/ascii/ascii.bif.h"
#include "zeek/threading/SerialTypes.h" #include "zeek/threading/SerialTypes.h"
@ -345,7 +344,8 @@ bool Ascii::DoUpdate() {
FailWarn(fail_on_invalid_lines, FailWarn(fail_on_invalid_lines,
Fmt("Not enough fields in line '%s' of %s. Found " Fmt("Not enough fields in line '%s' of %s. Found "
"%d fields, want positions %d and %d", "%d fields, want positions %d and %d",
line.c_str(), fname.c_str(), pos, fit.position, fit.secondary_position)); line.c_str(), fname.c_str(), pos, fit.position, fit.secondary_position),
! fail_on_invalid_lines);
if ( fail_on_invalid_lines ) { if ( fail_on_invalid_lines ) {
for ( int i = 0; i < fpos; i++ ) for ( int i = 0; i < fpos; i++ )
@ -374,8 +374,6 @@ bool Ascii::DoUpdate() {
if ( fit.secondary_position != -1 ) { if ( fit.secondary_position != -1 ) {
// we have a port definition :) // we have a port definition :)
assert(val->type == TYPE_PORT); assert(val->type == TYPE_PORT);
// Error(Fmt("Got type %d != PORT with secondary position!", val->type));
val->val.port_val.proto = formatter->ParseProto(stringfields[fit.secondary_position]); val->val.port_val.proto = formatter->ParseProto(stringfields[fit.secondary_position]);
} }
@ -395,8 +393,10 @@ bool Ascii::DoUpdate() {
delete[] fields; delete[] fields;
continue; continue;
} }
// If there's no error, then it makes sense to report the next error.
else
StopWarningSuppression();
// printf("fpos: %d, second.num_fields: %d\n", fpos, (*it).second.num_fields);
assert(fpos == NumFields()); assert(fpos == NumFields());
if ( Info().mode == MODE_STREAM ) if ( Info().mode == MODE_STREAM )
@ -408,6 +408,7 @@ bool Ascii::DoUpdate() {
if ( Info().mode != MODE_STREAM ) if ( Info().mode != MODE_STREAM )
EndCurrentSend(); EndCurrentSend();
StopWarningSuppression();
return true; return true;
} }

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning: ..<...>/Input::READER_ASCII: ../input.log, line 3: Not enough fields in line 'hello' of ../input.log. Found 0 fields, want positions 1 and -1
warning: ..<...>/Input::READER_ASCII: ../input.log, line 10: Not enough fields in line 'hello' of ../input.log. Found 0 fields, want positions 1 and -1
received termination signal
>>>

View file

@ -0,0 +1,50 @@
# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT
# @TEST-EXEC: btest-bg-wait 10
# @TEST-EXEC: sed 1d .stderr > .stderrwithoutfirstline
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderrwithoutfirstline
redef exit_only_after_terminate = T;
redef InputAscii::fail_on_invalid_lines = F;
@TEST-START-FILE input.log
#fields a b c
#types string bool bool
hello
hello
hello
hello
hello
hello
"hi" T F
hello
hello
hello
hello
hello
hello
hello
@TEST-END-FILE
type Key: record {
a: string;
};
type Val: record {
b: bool &log;
c: bool &log;
};
global test_table: table[string] of Val = table();
event zeek_init() {
Input::add_table([
$source="../input.log", $name="test_table",
$idx=Key, $val=Val, $destination=test_table,
$mode=Input::REREAD
]);
}
event Input::end_of_data(name: string, source:string) {
terminate();
}