Skip to content

fix(parsing): Timestamp error handling in dnstap parser #23072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/fix_dnstap_better_errors_timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix problem with parsing timestamp that could lead into panic in `dnstap-parser::DnstapParser::parse_dnstap_message_time`.

authors: wooffie
11 changes: 6 additions & 5 deletions lib/dnstap-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,10 @@ impl DnstapParser {

if type_ids.contains(&dnstap_message_type_id) {
DnstapParser::log_time(event, prefix.clone(), time_in_nanosec, "ns");

let timestamp = Utc
.timestamp_opt(time_sec.try_into().unwrap(), query_time_nsec)
.single()
.expect("invalid timestamp");
.ok_or("Invalid timestamp")?;
if let Some(timestamp_key) = log_schema().timestamp_key() {
DnstapParser::insert(event, prefix.clone(), timestamp_key, timestamp);
}
Expand Down Expand Up @@ -1346,9 +1345,9 @@ mod tests {
fn test_one_timestamp_parse(time_sec: u64, time_nsec: Option<u32>) -> Result<()> {
let mut event = LogEvent::default();
let root = owned_value_path!();
let type_ids = HashSet::new();
let type_ids = HashSet::from([1]);
DnstapParser::parse_dnstap_message_time(
&mut event, &root, time_sec, time_nsec, 0, None, &type_ids,
&mut event, &root, time_sec, time_nsec, 1, None, &type_ids,
)
}
// okay case
Expand All @@ -1362,7 +1361,9 @@ mod tests {
// overflow in add
assert!(
test_one_timestamp_parse((i64::MAX / 1_000_000_000) as u64, Some(u32::MAX)).is_err()
)
);
// cannot be parsed by timestamp_opt
assert!(test_one_timestamp_parse(96, Some(1616928816)).is_err());
}

#[test]
Expand Down