Skip to content

Commit

Permalink
Check for internal invariant violations in simple parser target (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-h-kastner-aws authored Dec 6, 2023
1 parent 4a87db3 commit 2f8c2d3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cedar-drt/fuzz/fuzz_targets/simple-parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,32 @@
#![no_main]

use cedar_drt_inner::fuzz_target;
use cedar_policy_core::parser::err::{ParseError, ToASTError};
use cedar_policy_core::parser::parse_policyset;

fuzz_target!(|input: String| {
// Ensure the parser does not crash
#[allow(clippy::single_match)]
match parse_policyset(&input) {
Ok(_) => (),
Err(_) => (),
Err(errs) => {
// Also check that we don't see a few specific errors.
// `AnnotationInvariantViolation` and `MembershipInvariantViolation`
// are documented as only being returned for internal invariant violations. It's not
// entirely clear when `MissingNodeData` might be returned, but I don't believe it
// should be possible, and, practically, it doesn't make this target fail.
assert!(
!errs.0.iter().any(|e| matches!(
e,
ParseError::ToAST(
ToASTError::AnnotationInvariantViolation
| ToASTError::MembershipInvariantViolation
| ToASTError::MissingNodeData
)
)),
"{:?}",
errs
)
}
};
});

0 comments on commit 2f8c2d3

Please sign in to comment.