]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: use u32 for InspectionBufferMultipleForList
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 6 May 2021 07:25:49 +0000 (09:25 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 25 Jun 2021 15:11:00 +0000 (17:11 +0200)
So that we do not have an endless loop casting index to
u16 and having more than 65536 buffers in one transaction

Changes for all protocols, even ones where it is impossible
to have such a pattern, so as to avoid bad pattern copy/paste
in the future

(cherry picked from commit 7d0a39412bb451443a4e19e6571ab86a0583214c)

rust/src/dns/dns.rs
rust/src/krb/detect.rs
rust/src/mqtt/detect.rs
src/detect-dns-query.c
src/detect-engine-mpm.h
src/detect-http2.c
src/detect-krb5-cname.c
src/detect-krb5-sname.c
src/detect-mqtt-subscribe-topic.c
src/detect-mqtt-unsubscribe-topic.c
src/detect-tls-certs.c

index 89f32e8e6703aa1d159ab2ca773d7da9e675cedb..1762182a042f071b911d2e82305940bbe3825cb8 100644 (file)
@@ -914,7 +914,7 @@ pub extern "C" fn rs_dns_state_get_tx_data(
 
 #[no_mangle]
 pub extern "C" fn rs_dns_tx_get_query_name(tx: &mut DNSTransaction,
-                                       i: u16,
+                                       i: u32,
                                        buf: *mut *const u8,
                                        len: *mut u32)
                                        -> u8
index 127903d73444869c102ea18e7bcd435cbee420fd..aa451782b8c37b07411588b42f40e09a2d4d5e42 100644 (file)
@@ -43,7 +43,7 @@ pub unsafe extern "C" fn rs_krb5_tx_get_errcode(tx:  &mut KRB5Transaction,
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_krb5_tx_get_cname(tx:  &mut KRB5Transaction,
-                                              i: u16,
+                                              i: u32,
                                               buffer: *mut *const u8,
                                               buffer_len: *mut u32)
                                               -> u8
@@ -61,7 +61,7 @@ pub unsafe extern "C" fn rs_krb5_tx_get_cname(tx:  &mut KRB5Transaction,
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_krb5_tx_get_sname(tx:  &mut KRB5Transaction,
-                                              i: u16,
+                                              i: u32,
                                               buffer: *mut *const u8,
                                               buffer_len: *mut u32)
                                               -> u8
index 2e02bdffababf87cbb37522c638e09060f58f177..fc8c297797c765ffd7c32db424476ac5b99f8671 100644 (file)
@@ -353,7 +353,7 @@ pub extern "C" fn rs_mqtt_tx_get_publish_message(
 
 #[no_mangle]
 pub extern "C" fn rs_mqtt_tx_get_subscribe_topic(tx: &MQTTTransaction,
-    i: u16,
+    i: u32,
     buf: *mut *const u8,
     len: *mut u32)
     -> u8
@@ -386,7 +386,7 @@ pub extern "C" fn rs_mqtt_tx_get_subscribe_topic(tx: &MQTTTransaction,
 
 #[no_mangle]
 pub extern "C" fn rs_mqtt_tx_get_unsubscribe_topic(tx: &MQTTTransaction,
-    i: u16,
+    i: u32,
     buf: *mut *const u8,
     len: *mut u32)
     -> u8
@@ -607,4 +607,4 @@ mod test {
         r = rs_mqtt_tx_get_subscribe_topic(&t, 4, &mut s, &mut slen);
         assert_eq!(r, 0);
     }
-}
\ No newline at end of file
+}
index 016d35fede133086f87e50eb7c2813f73a464e4c..c8798fa651dddcd9a97b014c3885f7948ab61970 100644 (file)
@@ -68,7 +68,7 @@ static void DetectDnsQueryRegisterTests(void);
 static int g_dns_query_buffer_id = 0;
 
 struct DnsQueryGetDataArgs {
-    int local_id;  /**< used as index into thread inspect array */
+    uint32_t local_id; /**< used as index into thread inspect array */
     void *txv;
 };
 
@@ -87,8 +87,7 @@ static InspectionBuffer *DnsQueryGetData(DetectEngineThreadCtx *det_ctx,
 
     const uint8_t *data;
     uint32_t data_len;
-    if (rs_dns_tx_get_query_name(cbdata->txv, (uint16_t)cbdata->local_id,
-                &data, &data_len) == 0) {
+    if (rs_dns_tx_get_query_name(cbdata->txv, cbdata->local_id, &data, &data_len) == 0) {
         return NULL;
     }
     InspectionBufferSetup(det_ctx, list_id, buffer, data, data_len);
@@ -103,7 +102,7 @@ static int DetectEngineInspectDnsQuery(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -160,7 +159,7 @@ static void PrefilterTxDnsQuery(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
     while(1) {
         // loop until we get a NULL
 
index 47518084745b7d26d5b38511aa237da3f8144bbd..e9ed4078ccb7b4187b57f7ef4f125c0302409de8 100644 (file)
@@ -125,7 +125,7 @@ typedef struct PrefilterMpmListId {
 } PrefilterMpmListId;
 
 struct MpmListIdDataArgs {
-    int local_id;  /**< used as index into thread inspect array */
+    uint32_t local_id; /**< used as index into thread inspect array */
     void *txv;
 };
 
index c8bc096bb669b636c3a566bf2beb2a31b9fd402a..11846af5bc06ac7460a987d9fc43f27da8fc6461 100644 (file)
@@ -703,7 +703,7 @@ static InspectionBuffer *GetHttp2HNameData(DetectEngineThreadCtx *det_ctx,
     uint32_t b_len = 0;
     const uint8_t *b = NULL;
 
-    if (rs_http2_tx_get_header_name(cbdata->txv, flags, (uint32_t)cbdata->local_id, &b, &b_len) != 1)
+    if (rs_http2_tx_get_header_name(cbdata->txv, flags, cbdata->local_id, &b, &b_len) != 1)
         return NULL;
     if (b == NULL || b_len == 0)
         return NULL;
@@ -725,7 +725,7 @@ static void PrefilterTxHttp2HName(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     while(1) {
         // loop until we get a NULL
@@ -769,7 +769,7 @@ static int DetectEngineInspectHttp2HeaderName(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -837,7 +837,7 @@ static InspectionBuffer *GetHttp2HeaderData(DetectEngineThreadCtx *det_ctx,
     uint32_t b_len = 0;
     const uint8_t *b = NULL;
 
-    if (rs_http2_tx_get_header(cbdata->txv, flags, (uint32_t)cbdata->local_id, &b, &b_len) != 1)
+    if (rs_http2_tx_get_header(cbdata->txv, flags, cbdata->local_id, &b, &b_len) != 1)
         return NULL;
     if (b == NULL || b_len == 0)
         return NULL;
@@ -859,7 +859,7 @@ static void PrefilterTxHttp2Header(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     while(1) {
         // loop until we get a NULL
@@ -902,7 +902,7 @@ static int DetectEngineInspectHttp2Header(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
index e7ca0fe84a898be83e50c0a93867fccc80ce5b08..3a71aaf5b476858fa79f29780d435b8af7b082df 100644 (file)
@@ -39,7 +39,7 @@
 static int g_krb5_cname_buffer_id = 0;
 
 struct Krb5PrincipalNameDataArgs {
-    int local_id;  /**< used as index into thread inspect array */
+    uint32_t local_id; /**< used as index into thread inspect array */
     void *txv;
 };
 
@@ -71,7 +71,7 @@ static InspectionBuffer *GetKrb5CNameData(DetectEngineThreadCtx *det_ctx,
     uint32_t b_len = 0;
     const uint8_t *b = NULL;
 
-    if (rs_krb5_tx_get_cname(cbdata->txv, (uint16_t)cbdata->local_id, &b, &b_len) != 1)
+    if (rs_krb5_tx_get_cname(cbdata->txv, cbdata->local_id, &b, &b_len) != 1)
         return NULL;
     if (b == NULL || b_len == 0)
         return NULL;
@@ -88,7 +88,7 @@ static int DetectEngineInspectKrb5CName(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -147,7 +147,7 @@ static void PrefilterTxKrb5CName(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     while(1) {
         // loop until we get a NULL
index fd33bb49bfbbcc9c7db13406c7e5a5b5bf549555..0ae6cf209798ce25a6c7915d956daee96d4c0898 100644 (file)
@@ -39,7 +39,7 @@
 static int g_krb5_sname_buffer_id = 0;
 
 struct Krb5PrincipalNameDataArgs {
-    int local_id;  /**< used as index into thread inspect array */
+    uint32_t local_id; /**< used as index into thread inspect array */
     void *txv;
 };
 
@@ -71,7 +71,7 @@ static InspectionBuffer *GetKrb5SNameData(DetectEngineThreadCtx *det_ctx,
     uint32_t b_len = 0;
     const uint8_t *b = NULL;
 
-    if (rs_krb5_tx_get_sname(cbdata->txv, (uint16_t)cbdata->local_id, &b, &b_len) != 1)
+    if (rs_krb5_tx_get_sname(cbdata->txv, cbdata->local_id, &b, &b_len) != 1)
         return NULL;
     if (b == NULL || b_len == 0)
         return NULL;
@@ -88,7 +88,7 @@ static int DetectEngineInspectKrb5SName(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -147,7 +147,7 @@ static void PrefilterTxKrb5SName(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     while(1) {
         // loop until we get a NULL
index 57ab2c4c03d612954415bc0b0a9b821ea1009537..25b4188cb048e1a813ee0fbe7b32d2444839a02a 100644 (file)
@@ -59,7 +59,7 @@ static int DetectMQTTSubscribeTopicSetup(DetectEngineCtx *, Signature *, const c
 static int g_mqtt_subscribe_topic_buffer_id = 0;
 
 struct MQTTSubscribeTopicGetDataArgs {
-    int local_id;
+    uint32_t local_id;
     void *txv;
 };
 
@@ -78,8 +78,7 @@ static InspectionBuffer *MQTTSubscribeTopicGetData(DetectEngineThreadCtx *det_ct
 
     const uint8_t *data;
     uint32_t data_len;
-    if (rs_mqtt_tx_get_subscribe_topic(cbdata->txv, (uint16_t)cbdata->local_id,
-                &data, &data_len) == 0) {
+    if (rs_mqtt_tx_get_subscribe_topic(cbdata->txv, cbdata->local_id, &data, &data_len) == 0) {
         return NULL;
     }
 
@@ -95,7 +94,7 @@ static int DetectEngineInspectMQTTSubscribeTopic(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -152,7 +151,7 @@ static void PrefilterTxMQTTSubscribeTopic(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
     while(1) {
         struct MQTTSubscribeTopicGetDataArgs cbdata = { local_id, txv };
         InspectionBuffer *buffer = MQTTSubscribeTopicGetData(det_ctx, ctx->transforms,
index 307f843ea41e5bea17b03248231efed9dc684aad..c4b9806ccfc96e2c5deb5c51b71f455f38ab4b65 100644 (file)
@@ -59,7 +59,7 @@ static int DetectMQTTUnsubscribeTopicSetup(DetectEngineCtx *, Signature *, const
 static int g_mqtt_unsubscribe_topic_buffer_id = 0;
 
 struct MQTTUnsubscribeTopicGetDataArgs {
-    int local_id;
+    uint32_t local_id;
     void *txv;
 };
 
@@ -78,8 +78,7 @@ static InspectionBuffer *MQTTUnsubscribeTopicGetData(DetectEngineThreadCtx *det_
 
     const uint8_t *data;
     uint32_t data_len;
-    if (rs_mqtt_tx_get_unsubscribe_topic(cbdata->txv, (uint16_t)cbdata->local_id,
-                &data, &data_len) == 0) {
+    if (rs_mqtt_tx_get_unsubscribe_topic(cbdata->txv, cbdata->local_id, &data, &data_len) == 0) {
         return NULL;
     }
 
@@ -95,7 +94,7 @@ static int DetectEngineInspectMQTTUnsubscribeTopic(
         const Signature *s,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
 {
-    int local_id = 0;
+    uint32_t local_id = 0;
 
     const DetectEngineTransforms *transforms = NULL;
     if (!engine->mpm) {
@@ -152,7 +151,7 @@ static void PrefilterTxMQTTUnsubscribeTopic(DetectEngineThreadCtx *det_ctx,
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    int local_id = 0;
+    uint32_t local_id = 0;
     while(1) {
         struct MQTTUnsubscribeTopicGetDataArgs cbdata = { local_id, txv };
         InspectionBuffer *buffer = MQTTUnsubscribeTopicGetData(det_ctx, ctx->transforms,
index 5eb7be2898af7a8081c89e60889f30707da84dee..92fb08840778511a28e214f4c4d07be822bee3ea 100644 (file)
@@ -71,7 +71,7 @@ static int PrefilterMpmTlsCertsRegister(DetectEngineCtx *de_ctx,
 static int g_tls_certs_buffer_id = 0;
 
 struct TlsCertsGetDataArgs {
-    int local_id;  /**< used as index into thread inspect array */
+    uint32_t local_id; /**< used as index into thread inspect array */
     SSLCertsChain *cert;
 };