From 1dcb54910993df71e0a27cfec83b23c69f92be12 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 26 Oct 2026 15:31:28 +0000 Subject: [PATCH] rust: keep the ffi logger out of the test binary Rust unit tests link without libsuricata, so a C reference anywhere in the reachable code makes the test binary unlinkable. The ffi logger calls SCLogMessage even under cfg(test), unlike the suricata crate's own, which has a print fallback. Any test that reaches AppLayerTxData::update_file_flags therefore breaks cargo test --lib whenever the debug feature is on: it fails the GitHub jobs that build with --enable-debug or --all-features while our own CI never sees it. Give log_message the same fallback behind cfg(any(test, feature = "testing")), the pattern applayer.rs already uses for set_event. --- rust/ffi/src/debug.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rust/ffi/src/debug.rs b/rust/ffi/src/debug.rs index dce64dcc32..671d18500f 100644 --- a/rust/ffi/src/debug.rs +++ b/rust/ffi/src/debug.rs @@ -19,7 +19,7 @@ use std::{ffi::CString, path::Path}; -use suricata_sys::sys::{SCError, SCLogMessage}; +use suricata_sys::sys::SCError; use suricata_sys::sys::{SCFatalErrorOnInitStatic, SCLogLevel}; /// The Suricata log-level. @@ -66,12 +66,13 @@ pub fn sclog(level: SCLogLevel, file: &str, line: u32, function: &str, message: } /// SCLogMessage wrapper. +#[cfg(not(any(test, feature = "testing")))] pub fn log_message( level: SCLogLevel, filename: &str, line: std::os::raw::c_uint, function: &str, module: &str, message: &str, ) -> SCError { unsafe { - SCLogMessage( + suricata_sys::sys::SCLogMessage( level, to_safe_cstring(filename).as_ptr(), line, @@ -82,6 +83,17 @@ pub fn log_message( } } +/// Unit tests do not link the C library: print instead of calling +/// SCLogMessage, like the fallback in the suricata crate's debug.rs. +#[cfg(any(test, feature = "testing"))] +pub fn log_message( + level: SCLogLevel, filename: &str, line: std::os::raw::c_uint, _function: &str, _module: &str, + message: &str, +) -> SCError { + println!("{}:{} <{:?}> -- {}", filename, line, level, message); + SCError::SC_OK +} + // Convert a &str into a CString by first stripping NUL bytes. fn to_safe_cstring(val: &str) -> CString { let mut safe = Vec::with_capacity(val.len());