]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/mpm: constify arg
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 17 Jun 2025 09:18:47 +0000 (11:18 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 18 Jun 2025 16:22:55 +0000 (18:22 +0200)
and make rust version use the correct integer type

Ticket: 7762

rust/src/core.rs
rust/src/ftp/ftp.rs
src/util-mpm-ac-ks.c
src/util-mpm-ac.c
src/util-mpm-hs.c
src/util-mpm.c
src/util-mpm.h

index 2280e28958ffbdb6ec9d121c172e85fae9fb328c..ed06bbd8711a13ef19624548faa7c5602f7ca76f 100644 (file)
@@ -18,7 +18,7 @@
 //! This module exposes items from the core "C" code to Rust.
 
 use std;
-use std::os::raw::{c_int, c_void};
+use std::os::raw::c_void;
 use suricata_sys::sys::{AppProto, AppProtoEnum, SCLogLevel};
 
 use crate::filecontainer::*;
@@ -72,8 +72,8 @@ macro_rules!BIT_U64 {
 /// cbindgen:ignore
 extern "C" {
     pub fn MpmAddPatternCI(
-        ctx: *const c_void, pat: *const libc::c_char, pat_len: c_int, _offset: c_int,
-        _depth: c_int, id: c_int, rule_id: c_int, _flags: c_int,
+        ctx: *const c_void, pat: *const libc::c_char, pat_len: u16, _offset: u16,
+        _depth: u16, id: u32, rule_id: u32, _flags: u8,
     ) -> c_void;
 }
 
index 154badf8c25ede149b9c2930ba8b41b49aa71d6f..1aa31251b515b5c870077e2fcea05018f539089c 100644 (file)
@@ -18,7 +18,7 @@
 use std;
 use std::ptr;
 use std::ffi::{CStr, CString};
-use std::os::raw::{c_char, c_int, c_void};
+use std::os::raw::{c_char, c_void};
 
 use crate::conf::{conf_get, get_memval};
 use crate::core::*;
@@ -141,11 +141,11 @@ pub unsafe extern "C" fn SCFTPSetMpmState(ctx: *const c_void) {
             MpmAddPatternCI(
                 ctx,
                 name_ptr,
-                len as c_int,
+                len as u16,
                 0,
                 0,
-                index as c_int,
-                index as c_int,
+                index as u32,
+                index as u32,
                 0,
             );
         }
index 665147744c8171b5f4781e845f0a14667c2deaa2..5e73dfd533b6ea34629f12e53dd83f13cb2676f8 100644 (file)
@@ -86,8 +86,8 @@
 
 void SCACTileInitCtx(MpmCtx *);
 void SCACTileDestroyCtx(MpmCtx *);
-int SCACTileAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
-                         uint32_t, SigIntId, uint8_t);
+int SCACTileAddPatternCI(
+        MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t);
 int SCACTileAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
                          uint32_t, SigIntId, uint8_t);
 int SCACTilePreparePatterns(MpmConfig *mpm_conf, MpmCtx *mpm_ctx);
@@ -1336,9 +1336,8 @@ uint32_t SCACTileSearchLarge(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thr
  * \retval  0 On success.
  * \retval -1 On failure.
  */
-int SCACTileAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                         uint16_t offset, uint16_t depth, uint32_t pid,
-                         SigIntId sid, uint8_t flags)
+int SCACTileAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     flags |= MPM_PATTERN_FLAG_NOCASE;
     return MpmAddPattern(mpm_ctx, pat, patlen, offset, depth,
index 9f4607f50e8ddcae719583bff5fcf263b3bc8bd4..4a151cec0f03520185609fd986d08a8bfa0781b9 100644 (file)
@@ -64,8 +64,8 @@
 
 void SCACInitCtx(MpmCtx *);
 void SCACDestroyCtx(MpmCtx *);
-int SCACAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
-                     uint32_t, SigIntId, uint8_t);
+int SCACAddPatternCI(
+        MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t);
 int SCACAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
                      uint32_t, SigIntId, uint8_t);
 int SCACPreparePatterns(MpmConfig *, MpmCtx *mpm_ctx);
@@ -1038,9 +1038,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
  * \retval  0 On success.
  * \retval -1 On failure.
  */
-int SCACAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                     uint16_t offset, uint16_t depth, uint32_t pid,
-                     SigIntId sid, uint8_t flags)
+int SCACAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     flags |= MPM_PATTERN_FLAG_NOCASE;
     return MpmAddPattern(mpm_ctx, pat, patlen, offset, depth, pid, sid, flags);
index a738a691c3e2539c416e88c2dc217288ed83e00b..c37c1731b386b637d641c0d08f1673e219cbd989 100644 (file)
@@ -55,8 +55,8 @@ void SCHSInitCtx(MpmCtx *);
 void SCHSInitThreadCtx(MpmCtx *, MpmThreadCtx *);
 void SCHSDestroyCtx(MpmCtx *);
 void SCHSDestroyThreadCtx(MpmCtx *, MpmThreadCtx *);
-int SCHSAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
-                     uint32_t, SigIntId, uint8_t);
+int SCHSAddPatternCI(
+        MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t);
 int SCHSAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t,
                      uint32_t, SigIntId, uint8_t);
 int SCHSPreparePatterns(MpmConfig *mpm_conf, MpmCtx *mpm_ctx);
@@ -128,7 +128,7 @@ static void SCHSSetAllocators(void)
  *
  * \retval hash A 32 bit unsigned hash.
  */
-static inline uint32_t SCHSInitHashRaw(uint8_t *pat, uint16_t patlen)
+static inline uint32_t SCHSInitHashRaw(const uint8_t *pat, uint16_t patlen)
 {
     uint32_t hash = patlen * pat[0];
     if (patlen > 1)
@@ -149,10 +149,8 @@ static inline uint32_t SCHSInitHashRaw(uint8_t *pat, uint16_t patlen)
  *
  * \retval hash A 32 bit unsigned hash.
  */
-static inline SCHSPattern *SCHSInitHashLookup(SCHSCtx *ctx, uint8_t *pat,
-                                              uint16_t patlen, uint16_t offset,
-                                              uint16_t depth, char flags,
-                                              uint32_t pid)
+static inline SCHSPattern *SCHSInitHashLookup(SCHSCtx *ctx, const uint8_t *pat, uint16_t patlen,
+        uint16_t offset, uint16_t depth, char flags, uint32_t pid)
 {
     uint32_t hash = SCHSInitHashRaw(pat, patlen);
 
@@ -272,9 +270,8 @@ static inline int SCHSInitHashAdd(SCHSCtx *ctx, SCHSPattern *p)
  * \retval  0 On success.
  * \retval -1 On failure.
  */
-static int SCHSAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                          uint16_t offset, uint16_t depth, uint32_t pid,
-                          SigIntId sid, uint8_t flags)
+static int SCHSAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     SCHSCtx *ctx = (SCHSCtx *)mpm_ctx->ctx;
 
@@ -1087,9 +1084,8 @@ uint32_t SCHSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
  * \retval  0 On success.
  * \retval -1 On failure.
  */
-int SCHSAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                     uint16_t offset, uint16_t depth, uint32_t pid,
-                     SigIntId sid, uint8_t flags)
+int SCHSAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     flags |= MPM_PATTERN_FLAG_NOCASE;
     return SCHSAddPattern(mpm_ctx, pat, patlen, offset, depth, pid, sid, flags);
index 9c7c18cfdaaf8bfd114a675b5fa414e4c67878dd..c2ff50f2d71ee61f74eb1028b1d4ea4f92aa2408 100644 (file)
@@ -255,9 +255,8 @@ int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
                                                    pid, sid, flags);
 }
 
-int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                    uint16_t offset, uint16_t depth,
-                    uint32_t pid, SigIntId sid, uint8_t flags)
+int MpmAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     return mpm_table[mpm_ctx->mpm_type].AddPatternNocase(mpm_ctx, pat, patlen,
                                                          offset, depth,
@@ -275,7 +274,7 @@ int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
  *
  * \retval hash A 32 bit unsigned hash.
  */
-static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen)
+static inline uint32_t MpmInitHashRaw(const uint8_t *pat, uint16_t patlen)
 {
     uint32_t hash = patlen * pat[0];
     if (patlen > 1)
@@ -296,10 +295,8 @@ static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen)
  *
  * \retval hash A 32 bit unsigned hash.
  */
-static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx,
-        uint8_t *pat, uint16_t patlen,
-        uint16_t offset, uint16_t depth,
-        uint8_t flags, uint32_t pid)
+static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx, const uint8_t *pat, uint16_t patlen,
+        uint16_t offset, uint16_t depth, uint8_t flags, uint32_t pid)
 {
     uint32_t hash = MpmInitHashRaw(pat, patlen);
 
@@ -435,9 +432,8 @@ static inline int MpmInitHashAdd(MpmCtx *ctx, MpmPattern *p)
  * \retval  0 On success.
  * \retval -1 On failure.
  */
-int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                            uint16_t offset, uint16_t depth, uint32_t pid,
-                            SigIntId sid, uint8_t flags)
+int MpmAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
 {
     SCLogDebug("Adding pattern for ctx %p, patlen %"PRIu16" and pid %" PRIu32,
                mpm_ctx, patlen, pid);
index 6c18828e8b9f62756294c03985183f037f5cf97d..14252f15841cdff4dc519dd2aaa998b7d65b2f2c 100644 (file)
@@ -170,7 +170,8 @@ typedef struct MpmTableElmt_ {
      *  \param flags pattern flags
      */
     int  (*AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t);
-    int  (*AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t);
+    int (*AddPatternNocase)(struct MpmCtx_ *, const uint8_t *, uint16_t, uint16_t, uint16_t,
+            uint32_t, SigIntId, uint8_t);
     int (*Prepare)(MpmConfig *, struct MpmCtx_ *);
     int (*CacheRuleset)(MpmConfig *);
     /** \retval cnt number of patterns that matches: once per pattern max. */
@@ -205,14 +206,12 @@ void MpmDestroyThreadCtx(MpmThreadCtx *mpm_thread_ctx, const uint16_t matcher);
 int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
                     uint16_t offset, uint16_t depth,
                     uint32_t pid, SigIntId sid, uint8_t flags);
-int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                    uint16_t offset, uint16_t depth,
-                    uint32_t pid, SigIntId sid, uint8_t flags);
+int MpmAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags);
 
 void MpmFreePattern(MpmCtx *mpm_ctx, MpmPattern *p);
 
-int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
-                            uint16_t offset, uint16_t depth, uint32_t pid,
-                            SigIntId sid, uint8_t flags);
+int MpmAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset,
+        uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags);
 
 #endif /* SURICATA_UTIL_MPM_H */