]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed some xcode static analysis issues
authorRuss Combs <rucombs@cisco.com>
Wed, 11 Jun 2014 15:46:08 +0000 (11:46 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 11 Jun 2014 15:46:08 +0000 (11:46 -0400)
27 files changed:
ChangeLog
src/detection/fpdetect.cc
src/file_api/file_service.cc
src/flow/flow_key.cc
src/hash/sfxhash.cc
src/ips_options/ips_byte_jump.cc
src/ips_options/ips_byte_test.cc
src/ips_options/ips_content.cc
src/ips_options/ips_isdataat.cc
src/ips_options/ips_pcre.cc
src/log/log_text.cc
src/log/sf_textlog.cc
src/managers/event_manager.cc
src/network_inspectors/port_scan/ipobj.cc
src/network_inspectors/port_scan/port_scan.cc
src/search_engines/acsmx2.cc
src/service_inspectors/http_inspect/hi_client.cc
src/service_inspectors/http_inspect/hi_norm.cc
src/service_inspectors/http_inspect/hi_server.cc
src/service_inspectors/nhttp_inspect/nhttp_enum.h
src/sfrt/sfrt_flat.cc
src/stream/tcp/tcp_session.cc
src/time/ppm.cc
src/utils/sf_email_attach_decode.cc
src/utils/sfportobject.cc
src/utils/stats.cc
src/utils/util.cc

index bcf9720b5b0a28756105bfe4045595421884b878..4d48623d9ccd1d7a9e97837da51968c2297a6d59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 87
 -- renamed api function typedefs to camel case for consistency and to match
    style guide
+-- fixed some Xcode static analysis issues
 
 86
 -- pulled in tom's latest nhttp_inpsect code
index 1724f98c311f6aba54a475102c341dff34195592..0f4c3bf38ba59d68b3e9cf2514d399dd906d222e 100644 (file)
@@ -561,7 +561,7 @@ static int rule_tree_match( void * id, void *tree, int index, void * data, void
             eval_data.p->packet_flags |= PKT_IP_RULE_2ND;
 
             /* Recurse, and evaluate with the inner IP */
-            rval = rule_tree_match(id, tree, index, data, NULL);
+            rule_tree_match(id, tree, index, data, NULL);
 
             eval_data.p->packet_flags &= ~PKT_IP_RULE_2ND;
             eval_data.p->packet_flags |= PKT_IP_RULE;
index 0365f10fd78ffcc24750ff33db95b5590f745c31..ae3e9a2b5dc63604d8094270ce8cfdf203d4b193 100644 (file)
@@ -327,8 +327,8 @@ static void printFileContext (FileContext* context)
     {
         used = snprintf(cur, unused, "\nProcessed size: %u\n",
                 (unsigned int)context->processed_bytes);
-        unused -= used;
-        cur += used;
+        //unused -= used;
+        //cur += used;
     }
 
     buf[sizeof(buf) - 1] = '\0';
index cbb9127ca6653e80a027e2f318e2121ac6e4f3f8..bf38ca746c61e0be1a7760b8d9ac9a8f8832729e 100644 (file)
@@ -282,8 +282,8 @@ uint32_t FlowKey::hash(SFHASHFCN*, unsigned char *d, int)
     {
         b += tmp;   /* mpls label */
     }
-    offset += 8;    /* skip past vlan/proto/ipver & mpls label */
 #ifdef HAVE_DAQ_ADDRESS_SPACE_ID
+    offset += 8;    /* skip past vlan/proto/ipver & mpls label */
     tmp2 = *(uint32_t*)(d+offset); /* after offset that has been moved */
     c += tmp2; /* address space id and 16bits of zero'd pad */
 #endif
index 3a48c5d5e01f8ea4a78ae012ead6c9f37fa09969..8825fc43afc5abee5055de8ce9dd5edd172b5575 100644 (file)
@@ -1059,8 +1059,6 @@ SO_PUBLIC int sfxhash_remove( SFXHASH * t, void * key)
     /* Modulus is slow */
     index   = hashkey & (t->nrows - 1);
 
-    hnode = t->table[index];
-
     for( hnode=t->table[index]; hnode; hnode=hnode->next )
     {
         if( !t->sfhashfcn->keycmp_fcn(hnode->key,key,t->keysize) )
index ee6a8a926d6280f7547ce792382f8d4ac575e3d9..93000ed5311086d56d9e3d0fc8a6e222eba17c16 100644 (file)
@@ -249,7 +249,7 @@ int ByteJumpOption::eval(Packet *p)
 
     /* save off whatever our ending pointer is */
     end_ptr = start_ptr + dsize;
-    base_ptr = start_ptr;
+    //base_ptr = start_ptr;
 
     /* Get values from byte_extract variables, if present. */
     if (bjd->offset_var >= 0 && bjd->offset_var < NUM_BYTE_EXTRACT_VARS)
index e06e4aebb4d00836e57d9d04a1646f50b5fe0e12..c196bb9c6e7347d5c2ad1b1e7676f77e21af2342 100644 (file)
@@ -289,7 +289,7 @@ int ByteTestOption::eval(Packet *p)
         start_ptr = (char *) p->data;
     }
 
-    base_ptr = start_ptr;
+    //base_ptr = start_ptr;
     end_ptr = start_ptr + dsize;
 
     DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,
index 0e98574d237790c1794deb25b0703f1a7efddf92..5b0f1a1b7f9e72797159149d8549bec72f915408 100644 (file)
@@ -575,7 +575,7 @@ static int uniSearchReal(const char *data, int dlen, PatternMatchData *pmd, int
     int success = 0;
     const char *start_ptr = data;
     const char *end_ptr = data + dlen;
-    const char *base_ptr = start_ptr;
+    const char *base_ptr;// = start_ptr;
     uint32_t extract_offset, extract_depth, extract_distance, extract_within;
 
     if(pmd->use_doe != 1)
index ce54eb7d8cd2f24a357991b10bcd7cb20a3aafb1..5e6a0e67f67f30b5805763885a9ae5a08a118528 100644 (file)
@@ -202,7 +202,7 @@ int IsDataAtOption::eval(Packet *p)
         start_ptr = p->data;
     }
 
-    base_ptr = start_ptr;
+    //base_ptr = start_ptr;
     end_ptr = start_ptr + dsize;
 
     if((isdata->flags & ISDATAAT_RELATIVE_FLAG) && doe_ptr)
index 091bc592670c6872cb748d591170542d3c58d5af..63cff4396e65e93752d88105b56abfa8c953e6bf 100644 (file)
@@ -271,7 +271,7 @@ int PcreOption::eval(Packet *p)
         start_ptr = p->data;
     }
 
-    base_ptr = start_ptr;
+    //base_ptr = start_ptr;
     end_ptr = start_ptr + dsize;
 
     /* doe_ptr's would be set by the previous content option */
index 5fca16ddf639722fce34e6ff42f7c2eba2c3d374..3d2c2611073b6e144136aa607abfd343c75d53f7 100644 (file)
@@ -1462,10 +1462,10 @@ void LogNetData (TextLog* log, const uint8_t* data, const int len, Packet *p)
 
     int offset = 0;
     char conv[] = "0123456789ABCDEF";   /* xlation lookup table */
-    int next_layer, ip_start, ip_ob_start, ip_ob_end, byte_pos, char_pos;
+    int ip_start, ip_ob_start, ip_ob_end, byte_pos, char_pos;
     int i;
 
-    next_layer = ip_start = byte_pos = char_pos = 0;
+    ip_start = byte_pos = char_pos = 0;
 
     ip_ob_start = ip_ob_end = -1;
 
@@ -1494,7 +1494,7 @@ void LogNetData (TextLog* log, const uint8_t* data, const int len, Packet *p)
 
     if(p && ScObfuscate() )
     {
-        next_layer =  p->next_layer;
+        int next_layer =  p->next_layer;
         for ( i = 0; i < next_layer; i++ )
         {
             if ( p->layers[i].proto == PROTO_IP4
@@ -1523,8 +1523,6 @@ void LogNetData (TextLog* log, const uint8_t* data, const int len, Packet *p)
     /* loop thru the whole buffer */
     while ( pb < end )
     {
-        i = 0;
-
         if (ScVerboseByteDump())
         {
             TextLog_Print(log, "0x%04X: ", offset);
index 4bf9afa925b64281a6e9899c553f3a3353437b22..8fdc52dfdf140273e398e40a0e741788170d6fc7 100644 (file)
@@ -89,6 +89,7 @@ TextLog* TextLog_Init (
     if ( !txt )
     {
         FatalError("Unable to allocate a TextLog(%u)!\n", maxBuf);
+        return nullptr;
     }
     txt->name = name ? SnortStrdup(name) : NULL;
     txt->file = TextLog_Open(txt->name);
index c84c363c271e8d4376d3e131804186c38ac77a17..4c81068435ac0cd42520f85c918e51171ab4bbab 100644 (file)
@@ -185,7 +185,10 @@ void EventManager::instantiate(
     Output* p = get_out(name);
 
     if ( !mod || !p )
+    {
         FatalError("unknown logger %s\n", name);
+        return;
+    }
 
     // emulate a config like name = { }
     mod->begin(name, 0, sc);
index 580747bd553ae2a1768137c890dd37f7904a0e9b..fb48a16c5bb86676bfbe284882891adee08279ba 100644 (file)
@@ -321,7 +321,8 @@ static int ip_parse(char *ipstr, sfip_t *ip, char *not_flag, PORTSET *portset, c
 
     /* Just to get the IP string out of the way */
     char* lasts = nullptr;
-    port_str = strtok_r(ipstr, " \t", &lasts);
+    strtok_r(ipstr, " \t", &lasts);
+    
     /* Is either the port after the 1st space, or NULL */
     port_str = strtok_r(NULL, " \t", &lasts);
 
index 39389703d07d43661e152d8660c7424928d63fe9..e89a5c6c43ded831245f5d61aaa535de4f16a820 100644 (file)
@@ -484,10 +484,9 @@ static int PortscanAlertTcp(Packet *p, PS_PROTO *proto, int)
             break;
 
         case PS_ALERT_PORTSWEEP_FILTERED:
-           event_ref = GeneratePSSnortEvent(p,GID_PORT_SCAN, PSNG_TCP_PORTSWEEP_FILTERED);
-           portsweep = 1;
-
-           return 0;
+            event_ref = GeneratePSSnortEvent(p,GID_PORT_SCAN, PSNG_TCP_PORTSWEEP_FILTERED);
+            portsweep = 1;
+            break;
 
         case PS_ALERT_DISTRIBUTED_FILTERED:
             event_ref = GeneratePSSnortEvent(p,GID_PORT_SCAN,
index f8fe78d2ff6468c9dab7cef3629b7ade3b7312aa..701175d3310e2e337dfe4399439c440bff733444 100644 (file)
@@ -1045,7 +1045,6 @@ static int Conv_Full_DFA_To_Banded(ACSM_STRUCT2 * acsm)
     int       cnt,m,k,i;
 
     for(k=0; k<acsm->acsmNumStates; k++) {
-        cnt=0;
 
         List_ConvToFull(acsm, (acstate_t)k, full );
 
@@ -1154,7 +1153,6 @@ static int Conv_Full_DFA_To_SparseBands(ACSM_STRUCT2 * acsm)
     acstate_t full[MAX_ALPHABET_SIZE];
 
     for(k=0; k<acsm->acsmNumStates; k++) {
-        cnt=0;
 
         List_ConvToFull(acsm, (acstate_t)k, full );
 
index 6caa8fcf72496833f797c731b5a9e25d200e854e..d41fe756c9a933ff373326f267e503b28501f0a6 100644 (file)
@@ -2370,7 +2370,6 @@ static inline const u_char *hi_client_extract_header(
         if (iRet == URI_END)
         {
             header_ptr->header.uri = version_string.uri_end + 1;
-            offset = (u_char *)p;
         }
         else
         {
@@ -2743,7 +2742,7 @@ int StatelessInspection(Packet *p, HI_SESSION *session, HttpsessionData *hsd, in
         //
         // uri_ptr.end points to end of URI & HTTP version identifier.
         if (hi_util_in_bounds(start, end, uri_ptr.uri_end + 1))
-            ptr = hi_client_extract_header(session, ServerConf, &header_ptr, uri_ptr.uri_end+1, end, hsd, stream_ins);
+            hi_client_extract_header(session, ServerConf, &header_ptr, uri_ptr.uri_end+1, end, hsd, stream_ins);
 
         if (header_ptr.header.uri)
         {
index 443123725189663530bc702f6f37286b16a36edb..7fa65806e092df4fc034762ca3999f4adde91661 100644 (file)
@@ -303,11 +303,6 @@ static int PercentDecode(HI_SESSION *session, const u_char *start,
         }
     }
 
-    /*
-    **  Initialize the normalization byte
-    */
-    iNorm = 0;
-
     /*
     **  hex values
     */
index 2abaa74fa088c7b51db00f48a8d5a4f149441bbe..1f8ad964de5ff6e260a2e82d04f031eb550996e8 100644 (file)
@@ -1420,7 +1420,7 @@ int HttpResponseInspection(HI_SESSION *session, Packet *p, const unsigned char *
     {
         if (hi_util_in_bounds(start, end, ptr))
         {
-            iRet = hi_server_inspect_body(session, sd, ptr, end, &body_ptr);
+            hi_server_inspect_body(session, sd, ptr, end, &body_ptr);
         }
     }
     else
@@ -1437,7 +1437,7 @@ int HttpResponseInspection(HI_SESSION *session, Packet *p, const unsigned char *
             }
             else
             {
-                iRet = hi_server_extract_status_msg(start, stat_code_ptr.uri_end ,
+                hi_server_extract_status_msg(start, stat_code_ptr.uri_end ,
                         end, &stat_msg_ptr);
 
                 if ( stat_msg_ptr.uri )
@@ -1540,7 +1540,7 @@ int HttpResponseInspection(HI_SESSION *session, Packet *p, const unsigned char *
 
                             if(hi_util_in_bounds(start, end, header_ptr.header.uri_end))
                             {
-                                iRet = hi_server_inspect_body(session, sd, header_ptr.header.uri_end,
+                                hi_server_inspect_body(session, sd, header_ptr.header.uri_end,
                                                                 end, &body_ptr);
                             }
                         }
index 5ee313f3caacd3d8aaf984dc8dba2e83d62ea4bf..d2a09b7ddb44ac7459fa808af668e36575909cf6 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef NHTTP_ENUM_H
 #define NHTTP_ENUM_H
 
+#include <stdint.h>
+
 #define NHTTP_GID 119
 
 namespace NHttpEnums {
index 1e707ae2b71e4ec7d05fc9c7ab17384da5ccd6a4..cb9f7e20164dc2cf54392cf4d8bd91f416014cce 100644 (file)
@@ -455,8 +455,6 @@ GENERIC sfrt_flat_dir8x_lookup(void *adr, table_flat_t* table)
             else
                 return NULL;
         }
-        subtable = (dir_sub_table_flat_t *)(&base[entry[index].value]);
-
     }
     else if (ip->family == AF_INET6)
     {
index d47916b2e273cb1f644c6a88021f1770a60f56af..08148f240736891e1b403756e29e22ac0275358f 100644 (file)
@@ -2378,7 +2378,7 @@ static int FlushStream(
     StreamSegment *ss = NULL, *seglist, *sr;
     uint16_t bytes_flushed = 0;
     uint16_t bytes_skipped = 0;
-    uint32_t bytes_queued = st->seg_bytes_logical;
+    STREAM5_DEBUG_WRAP(uint32_t bytes_queued = st->seg_bytes_logical;);
     uint32_t segs = 0;
     int ret;
     PROFILE_VARS;
@@ -2479,7 +2479,7 @@ static int FlushStream(
     STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE,
         "setting st->seglist_base_seq to 0x%X\n", st->seglist_base_seq););
 
-    bytes_queued -= bytes_flushed;
+    STREAM5_DEBUG_WRAP(bytes_queued -= bytes_flushed;);
 
     STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE,
         "flushed %d bytes / %d segs on stream, "
@@ -3654,7 +3654,7 @@ static int StreamQueue(StreamTracker *st, Packet *p, TcpDataBlock *tdb,
                         }
                     }
                     seq += overlap;
-                    slide = overlap;
+                    //slide = overlap;
                     if(SEQ_LEQ(seq_end, seq))
                     {
                         /*
@@ -3678,7 +3678,7 @@ static int StreamQueue(StreamTracker *st, Packet *p, TcpDataBlock *tdb,
                         STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE,
                                     "left overlap, honoring old data\n"););
                         seq += overlap;
-                        slide = overlap;
+                        //slide = overlap;
                         if(SEQ_LEQ(seq_end, seq))
                         {
                             /*
index 8bf98b6a3cad09b9d9518ebed15dc6b2f001cdbf..97698afb7130bf9a4ed5f360a8e9e5009141aced 100644 (file)
@@ -365,9 +365,7 @@ void ppm_pkt_log(ppm_cfg_t *ppm_cfg, Packet* p)
                         p->pkth->ts.tv_sec);
         }
 
-        if(filterEvent < 0)
-            filterEvent = 0;
-        else
+        if(filterEvent >= 0)
             AlertAction(p, potn);
     }
 
@@ -445,9 +443,7 @@ void ppm_rule_log(ppm_cfg_t *ppm_cfg, uint64_t pktcnt, Packet *p)
                                 p->pkth->ts.tv_sec);
                 }
 
-                if(filterEvent < 0)
-                    filterEvent = 0;
-                else
+                if(filterEvent >= 0)
                     AlertAction(p, otn);
             }
         }
@@ -501,9 +497,7 @@ void ppm_rule_log(ppm_cfg_t *ppm_cfg, uint64_t pktcnt, Packet *p)
                                 p->pkth->ts.tv_sec);
                 }
 
-                if(filterEvent < 0)
-                    filterEvent = 0;
-                else
+                if(filterEvent >= 0)
                     AlertAction(p, otn);
             }
         }
index e331cbe5c1d67b61f6c84e0d3afad85bbc62f364..0dbf1b4e9050b6c96afcfc0df24ff041a6af3d6a 100644 (file)
@@ -152,7 +152,6 @@ int sf_uudecode(uint8_t *src, uint32_t slen, uint8_t *dst, uint32_t dlen, uint32
     {
         if(*ptr == '\n')
         {
-            length = 0;
             sol = 1;
             ptr++;
             continue;
index e7bc7f9efa4979f757f75c02d144b66e452438ba..cb9ba9f409d712e6f92a0ad489ee9832f44c1412 100644 (file)
@@ -560,7 +560,10 @@ int PortObjectAddPortObject(PortObject * podst, PortObject * posrc, int *errflag
     {
         PortObjectItem *poi = PortObjectItemDup(po);
         if((ret = PortObjectAddItem(podst, poi, errflag)) != 0)
+        {
+            PortObjectItemFree(poi);
             return ret;
+        }
     }
 
     return ret;
@@ -690,7 +693,10 @@ PortObject * PortObjectDupPorts( PortObject * po )
       {
         poinew = PortObjectItemDup( poi );
         if(!poinew)
-              return 0;
+        {
+            free(ponew);
+            return NULL;
+        }
         PortObjectAddItem( ponew, poinew, NULL );
       }
     }
@@ -3375,7 +3381,6 @@ static PortObject *_POParsePort(POParser *pop)
         return NULL;
     }
 
-    hport = MAXPORTS-1;
     pop->token[0]=0;
 
     /* The string in pop should only be of the form <port> or <port>:<port> */
index 24c191e16c0078fb1c74132edbeabff05e07c8de..2108cc6dc2e51a8f6ecdd29d0e3515410e82d854 100644 (file)
@@ -244,8 +244,6 @@ void pc_sum()
 
 void DropStats()
 {
-    uint64_t pkts_recv = pc.total_from_daq;
-
     const DAQ_Stats_t* pkt_stats = &g_daq_stats;
 
 #ifdef PPM_MGR
@@ -253,10 +251,10 @@ void DropStats()
 #endif
 
     {
-        uint64_t pkts_drop, pkts_out, pkts_inj;
+        uint64_t pkts_out, pkts_inj;
 
-        pkts_recv = pkt_stats->hw_packets_received;
-        pkts_drop = pkt_stats->hw_packets_dropped;
+        uint64_t pkts_recv = pkt_stats->hw_packets_received;
+        uint64_t pkts_drop = pkt_stats->hw_packets_dropped;
 
         if ( pkts_recv > pkt_stats->packets_filtered
                        + pkt_stats->packets_received )
index 1e1a9cb8e3361df9dbd1b9b418989cc7f76ce07e..6a42e059c8c12f7adce8bac4981eb980cdab9bbe 100644 (file)
@@ -436,7 +436,6 @@ void InitGroups(int user_id, int group_id)
 
             if (initgroups(username, group_id) < 0)
             {
-                free(username);
                 FatalError("Can not initgroups(%s,%d)", username, group_id);
             }