From 70d078da514f8994816963c6a8a55bd206784e50 Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Tue, 14 Jan 2025 09:08:28 -0500 Subject: [PATCH] Clang-format and Rust format fixup --- clamd/clamd.c | 8 ++++---- clamscan/manager.c | 6 +++--- libclamav/cvd.c | 3 ++- libclamav/others.h | 2 +- libclamav_rust/build.rs | 8 +++++++- libclamav_rust/src/cdiff.rs | 10 +++++++++- libclamav_rust/src/ffi_util.rs | 4 ++-- libclamav_rust/src/fuzzy_hash.rs | 2 +- libclamav_rust/src/util.rs | 5 +---- unit_tests/check_clamav.c | 4 ++-- 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/clamd/clamd.c b/clamd/clamd.c index f46338f052..760eb5d621 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -172,7 +172,7 @@ int main(int argc, char **argv) pid_t mainpid = 0; mode_t old_umask = 0; const char *user_name = NULL; - char *cvdcertsdir = NULL; + char *cvdcertsdir = NULL; STATBUF statbuf; if (check_flevel()) @@ -597,9 +597,9 @@ int main(int argc, char **argv) // (which would've used the env var or hardcoded path) if (LSTAT(cvdcertsdir, &statbuf) == -1) { logg(LOGG_ERROR, - "ClamAV CA certificates directory is missing: %s\n" - "It should have been provided as a part of installation.", - cvdcertsdir); + "ClamAV CA certificates directory is missing: %s\n" + "It should have been provided as a part of installation.", + cvdcertsdir); ret = 1; break; } diff --git a/clamscan/manager.c b/clamscan/manager.c index ba5f577af3..f4c096133c 100644 --- a/clamscan/manager.c +++ b/clamscan/manager.c @@ -1258,9 +1258,9 @@ int scanmanager(const struct optstruct *opts) // (which would've used the env var or hardcoded path) if (LSTAT(cvdcertsdir, &statbuf) == -1) { logg(LOGG_ERROR, - "ClamAV CA certificates directory is missing: %s\n" - "It should have been provided as a part of installation.", - cvdcertsdir); + "ClamAV CA certificates directory is missing: %s\n" + "It should have been provided as a part of installation.", + cvdcertsdir); ret = 2; goto done; } diff --git a/libclamav/cvd.c b/libclamav/cvd.c index 4e44e13c8c..3b01a4cdd8 100644 --- a/libclamav/cvd.c +++ b/libclamav/cvd.c @@ -373,7 +373,8 @@ struct cl_cvd *cl_cvdhead(const char *file) if ((pt = strpbrk(head, "\n\r"))) *pt = 0; - for (i = bread - 1; i > 0 && (head[i] == ' ' || head[i] == '\n' || head[i] == '\r'); head[i] = 0, i--); + for (i = bread - 1; i > 0 && (head[i] == ' ' || head[i] == '\n' || head[i] == '\r'); head[i] = 0, i--) + ; return cl_cvdparse(head); } diff --git a/libclamav/others.h b/libclamav/others.h index 0d4d0b4f5d..f3625941aa 100644 --- a/libclamav/others.h +++ b/libclamav/others.h @@ -321,7 +321,7 @@ struct cl_engine { uint32_t ac_mindepth; uint32_t ac_maxdepth; char *tmpdir; - char* certs_directory; + char *certs_directory; uint32_t keeptmp; uint64_t engine_options; uint32_t cache_size; diff --git a/libclamav_rust/build.rs b/libclamav_rust/build.rs index cecad154e0..010703dc68 100644 --- a/libclamav_rust/build.rs +++ b/libclamav_rust/build.rs @@ -60,7 +60,13 @@ const BINDGEN_FUNCTIONS: &[&str] = &[ ]; // Generate bindings for these types (structs, enums): -const BINDGEN_TYPES: &[&str] = &["cli_matcher", "cli_ac_data", "cli_ac_result", "onedump_t", "cvd_t"]; +const BINDGEN_TYPES: &[&str] = &[ + "cli_matcher", + "cli_ac_data", + "cli_ac_result", + "onedump_t", + "cvd_t", +]; // Find the required functions and types in these headers: const BINDGEN_HEADERS: &[&str] = &[ diff --git a/libclamav_rust/src/cdiff.rs b/libclamav_rust/src/cdiff.rs index 04603d1043..6b40951f0b 100644 --- a/libclamav_rust/src/cdiff.rs +++ b/libclamav_rust/src/cdiff.rs @@ -19,7 +19,15 @@ */ use std::{ - collections::BTreeMap, ffi::{c_void, CStr, CString}, fs::{self, File, OpenOptions}, io::{prelude::*, BufReader, BufWriter, Read, Seek, SeekFrom, Write}, iter::*, mem::ManuallyDrop, os::raw::c_char, path::{Path, PathBuf}, str::{self, FromStr} + collections::BTreeMap, + ffi::{c_void, CStr, CString}, + fs::{self, File, OpenOptions}, + io::{prelude::*, BufReader, BufWriter, Read, Seek, SeekFrom, Write}, + iter::*, + mem::ManuallyDrop, + os::raw::c_char, + path::{Path, PathBuf}, + str::{self, FromStr}, }; use crate::{ diff --git a/libclamav_rust/src/ffi_util.rs b/libclamav_rust/src/ffi_util.rs index c141e2eceb..49c8887534 100644 --- a/libclamav_rust/src/ffi_util.rs +++ b/libclamav_rust/src/ffi_util.rs @@ -26,7 +26,7 @@ use std::{ os::raw::c_char, }; -use log::{warn}; +use log::warn; /// Wraps a call to a "result-returning function", allowing it to specify an /// error receiver and (optionally) result receiver. @@ -426,7 +426,7 @@ macro_rules! validate_str_param_null { /// /// The CString pointer must be valid /// The CString pointer must not be used after calling this function -#[export_name = "ffi_cstring_free"] +#[export_name = "ffi_cstring_free"] pub unsafe extern "C" fn ffi_cstring_free(cstring: *mut c_char) { if cstring.is_null() { warn!("Attempted to free a NULL CString pointer. Please report this at:: https://github.com/Cisco-Talos/clamav/issues"); diff --git a/libclamav_rust/src/fuzzy_hash.rs b/libclamav_rust/src/fuzzy_hash.rs index ac4f771365..51eda914a7 100644 --- a/libclamav_rust/src/fuzzy_hash.rs +++ b/libclamav_rust/src/fuzzy_hash.rs @@ -181,7 +181,7 @@ pub unsafe extern "C" fn _fuzzy_hash_load_subsignature( subsig_id: u32, err: *mut *mut FFIError, ) -> bool { - let hexsig = validate_str_param!(hexsig, err=err); + let hexsig = validate_str_param!(hexsig, err = err); let mut hashmap = ManuallyDrop::new(Box::from_raw(fuzzy_hashmap as *mut FuzzyHashMap)); diff --git a/libclamav_rust/src/util.rs b/libclamav_rust/src/util.rs index d836d11b0f..f9b927e149 100644 --- a/libclamav_rust/src/util.rs +++ b/libclamav_rust/src/util.rs @@ -145,10 +145,7 @@ pub unsafe fn scan_archive_metadata( /// /// No parameters may be NULL. #[export_name = "glob_rm"] -pub unsafe extern "C" fn glob_rm( - glob_str: *const c_char, - err: *mut *mut FFIError, -) -> bool { +pub unsafe extern "C" fn glob_rm(glob_str: *const c_char, err: *mut *mut FFIError) -> bool { let glob_str = validate_str_param!(glob_str); for entry in glob(glob_str).expect("Failed to read glob pattern") { diff --git a/unit_tests/check_clamav.c b/unit_tests/check_clamav.c index 41e7fadd55..dbbbbc8773 100644 --- a/unit_tests/check_clamav.c +++ b/unit_tests/check_clamav.c @@ -416,7 +416,7 @@ START_TEST(test_cl_load) struct cl_engine *engine; unsigned int sigs = 0; const char *testfile; - const char* cvdcertsdir; + const char *cvdcertsdir; ret = cl_init(CL_INIT_DEFAULT); ck_assert_msg(ret == CL_SUCCESS, "cl_init failed: %s", cl_strerror(ret)); @@ -443,7 +443,7 @@ START_TEST(test_cl_cvdverify) FILE *orig_fs; FILE *new_fs; char cvd_bytes[5000]; - const char* cvdcertsdir; + const char *cvdcertsdir; cvdcertsdir = getenv("CVD_CERTS_DIR"); ck_assert_msg(cvdcertsdir != NULL, "CVD_CERTS_DIR not set");