From: Russ Combs Date: Thu, 25 Sep 2014 12:55:12 +0000 (-0400) Subject: fixed some xcode static analysis warnings X-Git-Tag: 3.0.0-233~1398^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed214e96ecc8b58f7dcc628c1a0346b6ca57ed34;p=thirdparty%2Fsnort3.git fixed some xcode static analysis warnings --- diff --git a/ChangeLog b/ChangeLog index ed1e9b41f..29cf6d1a5 100644 --- 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 diff --git a/src/file_api/file_service.cc b/src/file_api/file_service.cc index 0b166f912..a82dbfced 100644 --- a/src/file_api/file_service.cc +++ b/src/file_api/file_service.cc @@ -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); diff --git a/src/filters/sfthd.cc b/src/filters/sfthd.cc index 07633012e..d2a1729ef 100644 --- a/src/filters/sfthd.cc +++ b/src/filters/sfthd.cc @@ -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; } diff --git a/src/flow/flow_cache.cc b/src/flow/flow_cache.cc index 6f42206e6..5464213a2 100644 --- a/src/flow/flow_cache.cc +++ b/src/flow/flow_cache.cc @@ -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() ) diff --git a/src/managers/inspector_manager.cc b/src/managers/inspector_manager.cc index 052266e99..c944acf4b 100644 --- a/src/managers/inspector_manager.cc +++ b/src/managers/inspector_manager.cc @@ -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 PHGlobalList; diff --git a/src/parser/cmd_line.cc b/src/parser/cmd_line.cc index 4b2975c4f..6b851548e 100644 --- a/src/parser/cmd_line.cc +++ b/src/parser/cmd_line.cc @@ -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); diff --git a/src/search_engines/bnfa_search.cc b/src/search_engines/bnfa_search.cc index 3c46de897..27d09c689 100644 --- a/src/search_engines/bnfa_search.cc +++ b/src/search_engines/bnfa_search.cc @@ -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) { diff --git a/src/service_inspectors/ftp_telnet/ftp_parse.cc b/src/service_inspectors/ftp_telnet/ftp_parse.cc index 68fd99b7e..eb2336dd8 100644 --- a/src/service_inspectors/ftp_telnet/ftp_parse.cc +++ b/src/service_inspectors/ftp_telnet/ftp_parse.cc @@ -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); diff --git a/src/service_inspectors/ftp_telnet/pp_ftp.cc b/src/service_inspectors/ftp_telnet/pp_ftp.cc index 6a7095968..f028412a9 100644 --- a/src/service_inspectors/ftp_telnet/pp_ftp.cc +++ b/src/service_inspectors/ftp_telnet/pp_ftp.cc @@ -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; } } diff --git a/src/service_inspectors/http_inspect/hi_server.cc b/src/service_inspectors/http_inspect/hi_server.cc index b968c299d..0186a082b 100644 --- a/src/service_inspectors/http_inspect/hi_server.cc +++ b/src/service_inspectors/http_inspect/hi_server.cc @@ -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; diff --git a/src/sfip/sf_vartable.cc b/src/sfip/sf_vartable.cc index 027f26e47..66f247630 100644 --- a/src/sfip/sf_vartable.cc +++ b/src/sfip/sf_vartable.cc @@ -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 */ diff --git a/src/target_based/sftarget_reader.cc b/src/target_based/sftarget_reader.cc index 291a9fd60..b54af61fe 100644 --- a/src/target_based/sftarget_reader.cc +++ b/src/target_based/sftarget_reader.cc @@ -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); diff --git a/src/utils/util_jsnorm.cc b/src/utils/util_jsnorm.cc index 3cb53043f..3d8c76217 100644 --- a/src/utils/util_jsnorm.cc +++ b/src/utils/util_jsnorm.cc @@ -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;