]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #5035: file_api : coverity fix
authorArnab Kumar Singh (arnsingh) <arnsingh@cisco.com>
Sat, 17 Jan 2026 17:07:00 +0000 (17:07 +0000)
committerLokesh Bevinamarad (lbevinam) <lbevinam@cisco.com>
Sat, 17 Jan 2026 17:07:00 +0000 (17:07 +0000)
Merge in SNORT/snort3 from ~ARNSINGH/snort3:coverity_fstat_fix to master

Squashed commit of the following:

commit bd20bb8eb0e070dbe5d3d08038a46aee6d911670
Author: Arnab <arnsingh@cisco.com>
Date:   Thu Nov 20 12:27:49 2025 +0530

    file_api : coverity fix

src/file_api/file_capture.cc
src/file_api/file_lib.cc

index efadcc12dd707c1f88d90310d804eea9ea5cdc81..026cb30b0bcc694003f700eea0914e2aa2f19c2e 100644 (file)
@@ -481,19 +481,11 @@ void FileCapture::store_file()
 
     const std::string& file_full_name = file_info->get_file_name();
 
-    /*Check whether the file exists*/
-    struct stat buffer;
-    if (stat (file_full_name.c_str(), &buffer) == 0)
+    FILE* fh = fopen(file_full_name.c_str(), "wx");
+    if (!fh)        
     {
         return;
     }
-
-    FILE* fh = fopen(file_full_name.c_str(), "w");
-    if (!fh )
-    {
-        return;
-    }
-
     // Check the file buffer
     uint8_t* buff = nullptr;
     int size = 0;
index 2c701da80960635c28cbd243763e08bdb776d31f..76998337719380b8bd14807f1b8afd63e30f19a6 100644 (file)
@@ -901,11 +901,11 @@ void FileContext::find_file_type_from_ips(Packet* pkt, const uint8_t* file_data,
         }
     }
     fp_eval_service_group(p, conf->snort_protocol_id);
-    if (set_file_context)
-        files->set_current_file_context(nullptr);
     /* Check whether file transfer is done or type depth is reached */
     if ((position == SNORT_FILE_END) || (position == SNORT_FILE_FULL) || depth_exhausted)
         finalize_file_type();
+    if (set_file_context)
+        files->set_current_file_context(nullptr);
 }
 
 void FileContext::process_file_type(Packet* pkt,const uint8_t* file_data, int data_size,