]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed some xcode static analysis warnings
authorRuss Combs <rucombs@cisco.com>
Thu, 25 Sep 2014 12:55:12 +0000 (08:55 -0400)
committerRuss Combs <rucombs@cisco.com>
Thu, 25 Sep 2014 12:55:12 +0000 (08:55 -0400)
13 files changed:
ChangeLog
src/file_api/file_service.cc
src/filters/sfthd.cc
src/flow/flow_cache.cc
src/managers/inspector_manager.cc
src/parser/cmd_line.cc
src/search_engines/bnfa_search.cc
src/service_inspectors/ftp_telnet/ftp_parse.cc
src/service_inspectors/ftp_telnet/pp_ftp.cc
src/service_inspectors/http_inspect/hi_server.cc
src/sfip/sf_vartable.cc
src/target_based/sftarget_reader.cc
src/utils/util_jsnorm.cc

index ed1e9b41f6ae9bd9746d3a4e26dd4c7ecd15c9e0..29cf6d1a515e7cf362f22152360a145ff186d979 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 -- pulled thread pinning from Josh
 -- snort.lua tweaks to back out random test foo
 -- additional valgrind tweaks
+-- fixed several Xcode static analysis warnings
 
 121
 -- valgrind fixes
index 0b166f91262a60d73845c6f3cf86f332191ead0e..a82dbfced5002df9b149a7c1cf7914613adb60a5 100644 (file)
@@ -324,15 +324,11 @@ static void printFileContext (FileContext* context)
         cur += used;
     }
 
-#if 0
     if (unused > 0)
     {
-        used = snprintf(cur, unused, "\nProcessed size: %u\n",
+        snprintf(cur, unused, "\nProcessed size: %u\n",
                 (unsigned int)context->processed_bytes);
-        //unused -= used;
-        //cur += used;
     }
-#endif
 
     buf[sizeof(buf) - 1] = '\0';
     printf("%s", buf);
index 07633012e6c264c7b5fcda4d313852c9a97dbd4f..d2a1729ef9178438d99d369e5e354b0566658ff9 100644 (file)
@@ -454,18 +454,7 @@ static int sfthd_create_threshold_local(
     }
 
     /*
-      If sfthd_node list is empty - add as head node
-    */
-    if( !sfthd_item->sfthd_node_list->count )
-    {
-#ifdef THD_DEBUG
-            printf("Threshold node added to head of list\n");fflush(stdout);
-#endif
-        sflist_add_head(sfthd_item->sfthd_node_list,sfthd_node);
-    }
-
-    /*
-      else add the sfthd_node using priority to determine where in the list
+      add the sfthd_node using priority to determine where in the list
       it belongs
 
       3.0 we can have only 1 threshold object but several suppression objects
@@ -476,7 +465,6 @@ static int sfthd_create_threshold_local(
       list, the tail node is either a supprssion node or the only pure
       thresholding node.
     */
-    else
     {
         SF_LNODE* lnode;
         NODE_DATA ndata;
@@ -512,6 +500,17 @@ static int sfthd_create_threshold_local(
         }
     }
 
+    /*
+     sfthd_node list is empty - add as head node
+     */
+    assert( !sfthd_item->sfthd_node_list->count );
+    {
+#ifdef THD_DEBUG
+        printf("Threshold node added to head of list\n");fflush(stdout);
+#endif
+        sflist_add_head(sfthd_item->sfthd_node_list,sfthd_node);
+    }
+
     return 0;
 }
 
index 6f42206e61a7b3e57467bd8cc7bb98546cf09c42..5464213a24a17f32c86d571222b5afa58781d4c0 100644 (file)
@@ -262,7 +262,7 @@ uint32_t FlowCache::prune_excess(bool memCheck, Flow *save_me)
             }
             else
             {
-                if ( flow->was_blocked() )
+                if ( flow && flow->was_blocked() )
                     blocks++;
 
                 if ( !hash_table->touch() )
index 052266e99dcc06e3582b8f5ef97f3b6213b2897f..c944acf4b93c68fc8c4180c58ab76a539ddc1779 100644 (file)
@@ -94,13 +94,18 @@ PHInstance::PHInstance(PHClass& p) : pp_class(p)
 {
     Module* mod = ModuleManager::get_module(p.api.base.name);
     handler = p.api.ctor(mod);
-    handler->set_api(&p.api);
-    handler->add_ref();
+
+    if ( handler )
+    {
+        handler->set_api(&p.api);
+        handler->add_ref();
+    }
 }
 
 PHInstance::~PHInstance()
 {
-    handler->rem_ref();
+    if ( handler )
+        handler->rem_ref();
 }
 
 typedef vector<PHGlobal*> PHGlobalList;
index 4b2975c4f07cf58226924098b09bc56a00a86f0c..6b851548e8e93cb82506a266604a5794712c1429 100644 (file)
@@ -151,13 +151,13 @@ SnortConfig* parse_cmd_line(int argc, char* argv[])
 
     // get special options first
     while ( al.get_arg(key, val) )
-        set(key, val, sc, false);
+        ::set(key, val, sc, false);
 
     // now get the rest
     al.reset();
 
     while ( al.get_arg(key, val) )
-        set(key, val, sc, true);
+        ::set(key, val, sc, true);
 
     check_flags(sc);
 
index 3c46de897a4db42196dbaf3df038483b72c00778..27d09c689d69bdbae703b602ba362fd48a776743 100644 (file)
@@ -196,6 +196,8 @@ void bnfa_init_xlatcase()
 */
 static void * bnfa_alloc( int n, int * m )
 {
+    if ( !n )
+        return nullptr;
     void * p = calloc(1,n);
     if( p ) {
         if(m) {
@@ -1019,6 +1021,7 @@ static int _bnfa_conv_list_to_csparse_array(bnfa_struct_t * bnfa)
     /* sanity check we have not overflowed our buffer */
     if( ps_index > nps ) {
         /* Fatal */
+        BNFA_FREE(pi,bnfa->bnfaNumStates*sizeof(bnfa_state_t),bnfa->nextstate_memory);
         return -1;
     }
 
@@ -1074,6 +1077,7 @@ static int _bnfa_conv_list_to_csparse_array(bnfa_struct_t * bnfa)
         /* check for buffer overflow again */
         if( ps_index > nps ) {
             /* Fatal */
+            BNFA_FREE(pi,bnfa->bnfaNumStates*sizeof(bnfa_state_t),bnfa->nextstate_memory);
             return -1;
         }
 
@@ -2257,6 +2261,7 @@ unsigned bnfaSearch( bnfa_struct_t * bnfa, unsigned char *Tx, int n,
             int (*Match)(void * id, void *tree, int index, void *data, void *neg_list),
             void *data, unsigned sindex, int* current_state )
 {
+    assert(current_state);
     int ret = 0;
 
     if (current_state) {
index 68fd99b7ea7d04cf8c26e9e432040e47b358b939..eb2336dd86d5494b516ca4add8253f758cde9192 100644 (file)
@@ -249,13 +249,13 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 OptFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));
                 if (OptFmt == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 curr_format = (char *)calloc(curr_len + 1, sizeof(char));
                 if (curr_format == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 strncpy(curr_format, start_ch, curr_len);
@@ -280,12 +280,11 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 curr_format = (char *)calloc(curr_len + 1, sizeof(char));
                 if (curr_format == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 strncpy(curr_format, start_ch, curr_len);
                 CurrFmt->format_string = curr_format;
-                curr_len = 0;
             }
             *format = curr_ch;
             return FTPP_SUCCESS;
@@ -297,7 +296,7 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));
                 if (NewFmt == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 if (curr_len > 0)
@@ -305,7 +304,7 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                     curr_format = (char *)calloc(curr_len + 1, sizeof(char));
                     if (curr_format == NULL)
                     {
-                        ParseError("Failed to allocate memory");
+                        FatalError("Failed to allocate memory");
                     }
 
                     strncpy(curr_format, start_ch, curr_len);
@@ -326,7 +325,7 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));
                 if (NewFmt == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 NewFmt->prev = LastNonOptFmt;
@@ -340,7 +339,7 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 NewFmt = (FTP_DATE_FMT *)calloc(1, sizeof(FTP_DATE_FMT));
                 if (NewFmt == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 NewFmt->prev = CurrFmt;
@@ -359,12 +358,11 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 curr_format = (char *)calloc(curr_len + 1, sizeof(char));
                 if (curr_format == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 strncpy(curr_format, start_ch, curr_len);
                 CurrFmt->format_string = curr_format;
-                curr_len = 0;
                 *format = curr_ch;
                 return FTPP_SUCCESS;
             }
@@ -382,12 +380,11 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
                 curr_format = (char *)calloc(curr_len + 1, sizeof(char));
                 if (curr_format == NULL)
                 {
-                    ParseError("Failed to allocate memory");
+                    FatalError("Failed to allocate memory");
                 }
 
                 strncpy(curr_format, start_ch, curr_len);
                 CurrFmt->format_string = curr_format;
-                curr_len = 0;
                 *format = curr_ch;
                 return FTPP_SUCCESS;
             }
@@ -410,13 +407,11 @@ static int ProcessDateFormat(FTP_DATE_FMT *dateFmt,
         curr_format = (char *)calloc(curr_len + 1, sizeof(char));
         if (curr_format == NULL)
         {
-            ParseError("Failed to allocate memory");
+            FatalError("Failed to allocate memory");
         }
 
         strncpy(curr_format, start_ch, curr_len);
         CurrFmt->format_string = curr_format;
-        start_ch = curr_ch;
-        curr_len = 0;
     }
 
     /* Should've closed all options & ORs  */
@@ -701,7 +696,7 @@ int ProcessFTPCmdValidity(
     HeadFmt = (FTP_PARAM_FMT *)calloc(1, sizeof(FTP_PARAM_FMT));
     if (HeadFmt == NULL)
     {
-        ParseError("Failed to allocate memory");
+        FatalError("Failed to allocate memory");
     }
 
     HeadFmt->type = e_head;
@@ -725,7 +720,7 @@ int ProcessFTPCmdValidity(
         FTPCmd = (FTP_CMD_CONF *)calloc(1, sizeof(FTP_CMD_CONF)+strlen(cmd));
         if (FTPCmd == NULL)
         {
-            ParseError("Failed to allocate memory");
+            FatalError("Failed to allocate memory");
         }
 
         strcpy(FTPCmd->cmd_name, cmd);
index 6a70959681022a58e74c4043ff988f1b9dc69aad..f028412a9d59d2c4d101a608c3eae5a09d5cc7e3 100644 (file)
@@ -942,7 +942,6 @@ static int check_ftp_param_validity(Packet *p,
                 if (iRet == FTPP_SUCCESS)
                 {
                     this_param = NextFmt->next_param+1;
-                    valid = 1;
                     break;
                 }
             }
index b968c299d746444ba3c7ba60734acea63487320a..0186a082b3699c61765bea1cb61af71550642fda 100644 (file)
@@ -1574,7 +1574,7 @@ static int HttpResponseInspection(HI_SESSION *session, Packet *p, const unsigned
                 alt_dsize = sizeof(HttpDecodeBuf.data);
             }
             /* not checking if sd== NULL as the body_ptr.uri = NULL when sd === NULL in hi_server_inspect_body */
-            if(sd->decomp_state && sd->decomp_state->decompress_data)
+            if(sd && sd->decomp_state && sd->decomp_state->decompress_data)
             {
                 status = SafeMemcpy(HttpDecodeBuf.data, Server->response.body,
                                             alt_dsize, HttpDecodeBuf.data, HttpDecodeBuf.data + sizeof(HttpDecodeBuf.data));
@@ -1588,7 +1588,7 @@ static int HttpResponseInspection(HI_SESSION *session, Packet *p, const unsigned
             }
             else
             {
-                if(sd->resp_state.last_pkt_chunked)
+                if(sd && sd->resp_state.last_pkt_chunked)
                 {
                     SetHttpDecode((uint16_t)alt_dsize);
                     Server->response.body = HttpDecodeBuf.data;
index 027f26e47c243da5863c3f7097ea820bf9078fce..66f24763068c3ae6764f14a44d2e44958b52727f 100644 (file)
@@ -218,7 +218,7 @@ SFIP_RET sfvt_add_str(vartable_t *table, const char *str, sfip_var_t **ipret)
     sfip_var_t *swp;
     sfip_var_t *p;
     int ret;
-    SFIP_RET status;
+    SFIP_RET status = SFIP_FAILURE;
 
     if(!table || !str || !ipret) return SFIP_FAILURE;
 
@@ -226,7 +226,7 @@ SFIP_RET sfvt_add_str(vartable_t *table, const char *str, sfip_var_t **ipret)
     var = sfvar_alloc(table, str, &status);
     if( var == NULL )
     {
-         return status;
+         return SFIP_FAILURE;
     }
 
     /* If this is an alias of another var, id will be set */
index 291a9fd602d87f7bb0327ce694f4ca6394d6844e..b54af61fec2ae81052fc3560dac6ff7bb0d1df1d 100644 (file)
@@ -256,6 +256,7 @@ int SFAT_AddHostEntryToMap(HostAttributeEntry* host)
     DEBUG_WRAP(PrintHostAttributeEntry(host););
 
     ipAddr = &host->ipAddr;
+    assert(ipAddr);
 
     ret = sfrt_insert(ipAddr, (unsigned char)ipAddr->bits, host,
                         RT_FAVOR_SPECIFIC, next_cfg->lookupTable);
index 3cb53043fd3679124954be9f26753864378f5311..3d8c76217dcd396e90df9812d2c7a7ddee455d2e 100644 (file)
@@ -606,7 +606,7 @@ int PNormDecode(char *src, uint16_t srclen, char *dst, uint16_t dstlen, uint16_t
         ptr++;
     } 
 
-    dst = s.output.data;
+    //dst = s.output.data;  FIXIT-L dead store; should be?
     *bytes_copied = s.output.len;
 
     return iRet;
@@ -1254,7 +1254,7 @@ int JSNormalizeDecode(char *src, uint16_t srclen, char *dst, uint16_t destlen, c
         (*ptr)++;
     }
 
-    dst = s.dest.data;
+    //dst = s.dest.data; FIXIT-L dead store; should be?
     *bytes_copied = s.dest.len;
 
     return RET_OK;