From: Shivani Bhardwaj Date: Wed, 6 May 2020 18:00:53 +0000 (+0530) Subject: rust: Add debug_validate_bug_on macro X-Git-Tag: suricata-6.0.0-beta1~420 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6db1f19d621a1a07bceddcbf58876324a87ea92d;p=thirdparty%2Fsuricata.git rust: Add debug_validate_bug_on macro This macro allows to check if certain parts of the code are reachable during fuzzing. --- diff --git a/configure.ac b/configure.ac index 127848234d..d738dfa99f 100644 --- a/configure.ac +++ b/configure.ac @@ -536,6 +536,7 @@ return 0; AC_DEFINE([DEBUG_VALIDATION],[1],[Enable (debug) validation code output]) fi ]) + AM_CONDITIONAL([DEBUG_VALIDATION], [test "x$enable_debug_validation" = "xyes"]) # profiling support AC_ARG_ENABLE(profiling, diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 0200df1d8a..a41d2c3fe2 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -15,6 +15,7 @@ lua = [] lua_int8 = ["lua"] strict = [] debug = [] +debug-validate = [] [dependencies] nom = "5.0" diff --git a/rust/Makefile.am b/rust/Makefile.am index 158d348b72..317f346515 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -19,6 +19,10 @@ if DEBUG RUST_FEATURES += debug endif +if DEBUG_VALIDATION +RUST_FEATURES += debug-validate +endif + if RUST_CROSS_COMPILE RUST_TARGET = --target $(host_triplet) endif diff --git a/rust/src/common.rs b/rust/src/common.rs index 668d55c86e..ce386e695b 100644 --- a/rust/src/common.rs +++ b/rust/src/common.rs @@ -14,6 +14,22 @@ macro_rules! take_until_and_consume ( ); ); +#[cfg(not(feature = "debug-validate"))] +#[macro_export] +macro_rules! debug_validate_bug_on ( + ($item:expr) => {}; +); + +#[cfg(feature = "debug-validate")] +#[macro_export] +macro_rules! debug_validate_bug_on ( + ($item:expr) => { + if $item { + panic!("Condition check failed"); + } + }; +); + /// Convert a String to C-compatible string /// /// This function will consume the provided data and use the underlying bytes to construct a new