]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: Add debug_validate_bug_on macro
authorShivani Bhardwaj <shivanib134@gmail.com>
Wed, 6 May 2020 18:00:53 +0000 (23:30 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 19 May 2020 17:58:12 +0000 (19:58 +0200)
This macro allows to check if certain parts of the code are reachable
during fuzzing.

configure.ac
rust/Cargo.toml.in
rust/Makefile.am
rust/src/common.rs

index 127848234dc057583a175e1e0846c9f4dcd775e7..d738dfa99f24586f521270b7108c9866d2e142da 100644 (file)
@@ -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,
index 0200df1d8af014deffbf84accd8c59c2bc21e770..a41d2c3fe2dd474a0ed3a102baa127ea23f7660e 100644 (file)
@@ -15,6 +15,7 @@ lua = []
 lua_int8 = ["lua"]
 strict = []
 debug = []
+debug-validate = []
 
 [dependencies]
 nom = "5.0"
index 158d348b723dfe9830ff337e4063a88cea3ddd4a..317f346515d0bd3abba536a1fbfc17bbb5a242e1 100644 (file)
@@ -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
index 668d55c86e0be0a03969377d06ff918a8dd8b318..ce386e695b7f9ba7553d3090564b8e3869e09f75 100644 (file)
@@ -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