]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2300 in SNORT/snort3 from ~MIALTIZE/snort3:32bit to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 30 Jun 2020 02:00:48 +0000 (02:00 +0000)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 30 Jun 2020 02:00:48 +0000 (02:00 +0000)
Squashed commit of the following:

commit 892e1b978f4e4f73e8fa30d1279ea09b7db2fe32
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Jun 29 18:17:40 2020 -0400

    http2_inspect: Make print_flow_issues() regtest-only

commit 63fce83f2b8689c0eb81053c643a5af9123f94a0
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Jun 29 18:09:40 2020 -0400

    build: Eradicate u_int usage

    As a bonus, this fixes the Alpine Linux build.

commit 7a1733662671c9e178d7f00e9ce1252df5e8a56a
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Jun 29 11:35:41 2020 -0400

    build: Miscellaneous 32-bit build fixes

14 files changed:
daqs/daq_hext.c
src/actions/act_react.cc
src/codecs/ip/cd_icmp4.cc
src/detection/tag.cc
src/file_api/file_cache.cc
src/helpers/sigsafe.cc
src/ips_options/asn1_util.cc
src/log/log_text.cc
src/main/analyzer.cc
src/network_inspectors/appid/appid_config.h
src/network_inspectors/packet_tracer/packet_tracer.cc
src/network_inspectors/packet_tracer/packet_tracer.h
src/service_inspectors/http2_inspect/http2_inspect.cc
src/utils/util.cc

index 59cceeda774c75cf4717cea20fc07a0eeae6721c..88633d405140945fe47da3446a2872a41c92cc15 100644 (file)
@@ -27,6 +27,7 @@
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -240,19 +241,44 @@ static void IpAddr(uint32_t* addr, char const* ip)
 
 static bool parse_flowstats(DAQ_MsgType type, const char* line, HextMsgDesc *desc)
 {
-#define FLOWSTATS_FORMAT "%d %d %d %d %s %hu %s %hu %u %lu %lu %lu %lu %lu %lu %hhu %ld %ld %hu %hu %hhu"
+#define FLOWSTATS_FORMAT \
+    "%" SCNi32 " "  /* ingressZone */   \
+    "%" SCNi32 " "  /* egressZone */    \
+    "%" SCNi32 " "  /* ingressIntf */   \
+    "%" SCNi32 " "  /* egressIntf */    \
+    "%s "           /* srcAddr */       \
+    "%" SCNu16 " "  /* initiatorPort */ \
+    "%s "           /* dstAddr */       \
+    "%" SCNu16 " "  /* responderPort */ \
+    "%" SCNu32 " "  /* opaque */        \
+    "%" SCNu64 " "  /* initiatorPkts */ \
+    "%" SCNu64 " "  /* responderPkts */ \
+    "%" SCNu64 " "  /* initiatorPktsDropped */  \
+    "%" SCNu64 " "  /* responderPktsDropped */  \
+    "%" SCNu64 " "  /* initiatorBytesDropped */ \
+    "%" SCNu64 " "  /* responderBytesDropped */ \
+    "%" SCNu8  " "  /* isQoSAppliedOnSrcIntf */ \
+    "%" SCNu32 " "  /* sof_timestamp.tv_sec */  \
+    "%" SCNu32 " "  /* eof_timestamp.tv_sec */  \
+    "%" SCNu16 " "  /* vlan_tag */      \
+    "%" SCNu16 " "  /* address_space_id */  \
+    "%" SCNu8       /* protocol */
 #define FLOWSTATS_ITEMS 21
     Flow_Stats_t* f = &desc->flowstats;
     char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
+    uint32_t sof_sec, eof_sec;
     int rval = sscanf(line, FLOWSTATS_FORMAT, &f->ingressZone, &f->egressZone, &f->ingressIntf,
             &f->egressIntf, srcaddr, &f->initiatorPort, dstaddr, &f->responderPort, &f->opaque,
             &f->initiatorPkts, &f->responderPkts, &f->initiatorPktsDropped, &f->responderPktsDropped,
             &f->initiatorBytesDropped, &f->responderBytesDropped, &f->isQoSAppliedOnSrcIntf,
-            &f->sof_timestamp.tv_sec, &f->eof_timestamp.tv_sec, &f->vlan_tag, &f->address_space_id,
+            &sof_sec, &eof_sec, &f->vlan_tag, &f->address_space_id,
             &f->protocol);
     if (rval != FLOWSTATS_ITEMS)
         return false;
 
+    f->sof_timestamp.tv_sec = sof_sec;
+    f->eof_timestamp.tv_sec = eof_sec;
+
     desc->msg.type = type;
     desc->msg.hdr_len = sizeof(desc->flowstats);
     desc->msg.hdr = &desc->flowstats;
index 74910cc045e9356c838248871055c2324d4282ce..c0befba6e8d0d592fc9dd4ed527b7525750db098 100644 (file)
@@ -218,8 +218,6 @@ bool ReactModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("page") )
         return getpage(v.get_string());
-    else
-        return false;
 
     return true;
 }
index 684de2cdb93c162380cafd173ff2ab83d016150f..9f31bb111db6e917ea4dacfaabe2a5ea06914699 100644 (file)
@@ -548,7 +548,7 @@ void Icmp4Codec::log(TextLog* const log, const uint8_t* raw_pkt,
     case icmp::IcmpType::ADDRESSREPLY:
         TextLog_Print(log, "ID: %u  Seq: %u  ADDRESS REPLY: 0x%08X",
             ntohs(icmph->s_icmp_id), ntohs(icmph->s_icmp_seq),
-            (u_int)ntohl(icmph->s_icmp_mask));
+            ntohl(icmph->s_icmp_mask));
         break;
 
     default:
index b7c2c213a3c45eea1534c567ca22f73071d7268c..6364511b0ce83a5831d90af22ce641765593165e 100644 (file)
@@ -562,7 +562,7 @@ int CheckTagList(Packet* p, Event& event, void** log_list)
         }
     }
 
-    if ( (u_int)(p->pkth->ts.tv_sec) > last_prune_time + TAG_PRUNE_QUANTUM )
+    if ( (unsigned)(p->pkth->ts.tv_sec) > last_prune_time + TAG_PRUNE_QUANTUM )
     {
         PruneTagCache(p->pkth->ts.tv_sec, 0);
         last_prune_time = p->pkth->ts.tv_sec;
index b90f6b77895fc020a2429446bbfa1925c3bf8cd0..fd581536534d716c69fa6a987205991000542ca8 100644 (file)
@@ -133,7 +133,7 @@ FileContext* FileCache::add(const FileHashKey& hashKey, int64_t timeout)
     struct timeval now;
     packet_gettimeofday(&now);
 
-    struct timeval time_to_add = { timeout, 0 };
+    struct timeval time_to_add = { static_cast<time_t>(timeout), 0 };
     timeradd(&now, &time_to_add, &new_node.cache_expire_time);
 
     new_node.file = new FileContext;
@@ -183,7 +183,7 @@ FileContext* FileCache::find(const FileHashKey& hashKey, int64_t timeout)
     }
 
     struct timeval next_expire_time;
-    struct timeval time_to_add = { timeout, 0 };
+    struct timeval time_to_add = { static_cast<time_t>(timeout), 0 };
     timeradd(&now, &time_to_add, &next_expire_time);
 
     //  Refresh the timer on the cache.
@@ -311,7 +311,7 @@ bool FileCache::apply_verdict(Packet* p, FileContext* file_ctx, FileVerdict verd
 
             if (!timerisset(&file_ctx->pending_expire_time))
             {
-                add_time = { lookup_timeout, 0 };
+                add_time = { static_cast<time_t>(lookup_timeout), 0 };
                 timeradd(&now, &add_time, &file_ctx->pending_expire_time);
 
                 if (PacketTracer::is_active())
index 332b9dd513769416f993d45a29d0de81be4ab934..2d273bee3680fde834ce8d946c641a040d2f6142 100644 (file)
@@ -213,7 +213,7 @@ void SigSafePrinter::write_string(const char* str)
 {
     size_t len = strlen(str);
     if (fd >= 0)
-        write(fd, str, len);
+        (void) write(fd, str, len);
     else if (buf)
     {
         if (len > buf_size - buf_idx - 1)
index caa87fa913b64e43ebcd99a6f178a7516854b71c..012eebbc7bd34a0a12dcc222d81d09d79649d3e4 100644 (file)
@@ -152,7 +152,7 @@ void asn1_free_mem()
 **  tag numbers, etc.
 **
 **  @param ASN1_DATA ptr to data
-**  @param u_int ptr to tag num
+**  @param unsigned ptr to tag num
 **
 **  @return integer
 **
@@ -161,10 +161,10 @@ void asn1_free_mem()
 **  @retval ASN1_ERR_OOB encoding goes out of bounds
 **  @retval ASN1_ERR_NULL_MEM function arguments are NULL
 */
-static int asn1_decode_tag_num_ext(ASN1_DATA* asn1_data, u_int* tag_num)
+static int asn1_decode_tag_num_ext(ASN1_DATA* asn1_data, unsigned* tag_num)
 {
     int iExtension = 0;
-    u_int new_tag_num;
+    unsigned new_tag_num;
 
     if (!asn1_data || !tag_num)
         return ASN1_ERR_NULL_MEM;
@@ -305,11 +305,11 @@ static int asn1_decode_len_type(const uint8_t* data)
 **  @retval ASN1_ERR_OOB out of bounds condition
 **  @retval ASN1_OK function successful
 */
-static int asn1_decode_len_ext(ASN1_DATA* asn1_data, u_int* size)
+static int asn1_decode_len_ext(ASN1_DATA* asn1_data, unsigned* size)
 {
     int iBytes;
     int iCtr;
-    u_int new_size;
+    unsigned new_size;
 
     if (!asn1_data || !size)
         return ASN1_ERR_NULL_MEM;
@@ -487,10 +487,10 @@ static int asn1_is_eoc(ASN1_TYPE* asn1)
 **  @retval ASN1_ERR_INVALID_ARG invalid argument
 **  @retval ASN1_ERR_OOB out of bounds
 */
-static int asn1_decode_type(const uint8_t** data, u_int* len, ASN1_TYPE** asn1_type)
+static int asn1_decode_type(const uint8_t** data, unsigned* len, ASN1_TYPE** asn1_type)
 {
     ASN1_DATA asn1data;
-    u_int uiRawLen;
+    unsigned uiRawLen;
     int iRet;
 
     if (!*data)
@@ -638,7 +638,7 @@ valid:
 **  @retval  ASN1_OK function successful
 **  @retval !ASN1_OK lots of error conditions, figure it out
 */
-int asn1_decode(const uint8_t* data, u_int len, ASN1_TYPE** asn1_type)
+int asn1_decode(const uint8_t* data, unsigned len, ASN1_TYPE** asn1_type)
 {
     ASN1_TYPE* cur;
     ASN1_TYPE* child = nullptr;
@@ -646,7 +646,7 @@ int asn1_decode(const uint8_t* data, u_int len, ASN1_TYPE** asn1_type)
     ASN1_TYPE* asnstack[ASN1_MAX_STACK];
 
     const uint8_t* end;
-    u_int con_len;
+    unsigned con_len;
     int index = 0;
     int iRet;
 
index 4fc942c0ddbeff56432db8352bc5513123222e09..6dfc9bbe670ea120317b2b1a34668130badc0926 100644 (file)
@@ -1005,7 +1005,7 @@ void LogICMPHeader(TextLog* log, Packet* p)
     case ICMP_ADDRESSREPLY:
         TextLog_Print(log, "ID: %u  Seq: %u  ADDRESS REPLY: 0x%08X",
             ntohs(p->ptrs.icmph->s_icmp_id), ntohs(p->ptrs.icmph->s_icmp_seq),
-            (u_int)ntohl(p->ptrs.icmph->s_icmp_mask));
+            ntohl(p->ptrs.icmph->s_icmp_mask));
         break;
 
     default:
index 98c193b013b13a6d0908dc1003b5cd770a3838d7..152736503bf1249093df587ddb865a47f633789f 100644 (file)
@@ -96,7 +96,7 @@ public:
     RetryQueue(unsigned interval_ms)
     {
         assert(interval_ms > 0);
-        interval = { interval_ms / 1000, static_cast<suseconds_t>((interval_ms % 1000) * 1000) };
+        interval = { static_cast<time_t>(interval_ms / 1000), static_cast<suseconds_t>((interval_ms % 1000) * 1000) };
     }
 
     ~RetryQueue()
@@ -575,7 +575,7 @@ void Analyzer::idle()
     struct timeval now, increment;
     unsigned int timeout = SnortConfig::get_conf()->daq_config->timeout;
     packet_gettimeofday(&now);
-    increment = { timeout / 1000, static_cast<suseconds_t>((timeout % 1000) * 1000) };
+    increment = { static_cast<time_t>(timeout / 1000), static_cast<suseconds_t>((timeout % 1000) * 1000) };
     timeradd(&now, &increment, &now);
     packet_time_update(&now);
 
index 8b06d9f3c3a937d73b30dbbacef883c9a686f541..e9d56104c1515ca381446833a1d7a9413dc0aad7 100644 (file)
@@ -61,8 +61,8 @@ public:
     uint32_t first_decrypted_packet_debug = 0;
 #endif
     bool log_stats = false;
-    unsigned long app_stats_period = 300;
-    unsigned long app_stats_rollover_size = 0;
+    uint32_t app_stats_period = 300;
+    uint32_t app_stats_rollover_size = 0;
     const char* app_detector_dir = nullptr;
     std::string tp_appid_path = "";
     std::string tp_appid_config = "";
index 59e51dc973f64b0ab75faed4030d3cb4dcb52b8c..cf16d8163a9f2037cea95443022d646472af3f00 100644 (file)
@@ -129,7 +129,7 @@ void PacketTracer::log(const char* format, ...)
 
     va_list ap;
     va_start(ap, format);
-    s_pkt_trace->log(format, ap);
+    s_pkt_trace->log_va(format, ap);
     va_end(ap);
 }
 
@@ -140,7 +140,7 @@ void PacketTracer::log(TracerMute mute, const char* format, ...)
 
     va_list ap;
     va_start(ap, format);
-    s_pkt_trace->log(format, ap);
+    s_pkt_trace->log_va(format, ap);
     va_end(ap);
 
     s_pkt_trace->mutes[mute] = true;
@@ -240,7 +240,7 @@ PacketTracer::~PacketTracer()
     }
 }
 
-void PacketTracer::log(const char* format, va_list ap)
+void PacketTracer::log_va(const char* format, va_list ap)
 {
     // FIXIT-L Need to find way to add 'PktTracerDbg' string as part of format string.
     std::string dbg_str;
index 413cb3514590d1e2316f7d04182fd8c3ebf05fce..8aae7a0411cbcb55f62675b6038b2d0bb2af5442 100644 (file)
@@ -94,7 +94,7 @@ protected:
     template<typename T = PacketTracer> static void _thread_init();
 
     // non-static functions
-    void log(const char*, va_list);
+    void log_va(const char*, va_list);
     void add_ip_header_info(const snort::Packet&);
     void add_eth_header_info(const snort::Packet&);
     void add_packet_type_info(const snort::Packet&);
index cfc889052ba4fec95de089e16210a9c393e38254..27e304f7bc9d324a1545f938fde8a683f3341266 100644 (file)
@@ -38,7 +38,9 @@ using namespace snort;
 using namespace HttpCommon;
 using namespace Http2Enums;
 
+#ifdef REG_TEST
 static void print_flow_issues(FILE*, Http2Infractions* const, Http2EventGen* const);
+#endif
 
 Http2Inspect::Http2Inspect(const Http2ParaList* params_) : params(params_)
 {
@@ -177,9 +179,11 @@ void Http2Inspect::clear(Packet* p)
     stream->clear_frame();
 }
 
+#ifdef REG_TEST
 static void print_flow_issues(FILE* output, Http2Infractions* const infractions,
     Http2EventGen* const events)
 {
     fprintf(output, "Infractions: %016" PRIx64 ", Events: %016" PRIx64 "\n\n",
         infractions->get_raw(), events->get_raw());
 }
+#endif
index 0694efbb100d1e047f9d26ecbaa3609695bafc19..d7e0f527fda7c0ec576d1f02c2dc07151cfc8df2 100644 (file)
@@ -187,14 +187,14 @@ void ts_print(const struct timeval* tvp, char* timebuf)
             "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
             year, lt->tm_mon + 1, lt->tm_mday,
             s / 3600, (s % 3600) / 60, s % 60,
-            (u_int)tvp->tv_usec);
+            (unsigned)tvp->tv_usec);
     }
     else
     {
         (void)SnortSnprintf(timebuf, TIMEBUF_SIZE,
             "%02d/%02d-%02d:%02d:%02d.%06u", lt->tm_mon + 1,
             lt->tm_mday, s / 3600, (s % 3600) / 60, s % 60,
-            (u_int)tvp->tv_usec);
+            (unsigned)tvp->tv_usec);
     }
 }