]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-file: change file size computation
authorEric Leblond <eric@regit.org>
Wed, 18 Jan 2017 19:08:21 +0000 (11:08 -0800)
committerEric Leblond <eric@regit.org>
Thu, 19 Jan 2017 18:29:22 +0000 (10:29 -0800)
The file size returned by FileSize is invalid if file store is not
used so we introduce a new size field in File structure that is used
to store the size.

src/util-file.c
src/util-file.h

index a327f139358c939b62b73f49e05c2b53b8f397fa..8148f7a2ea2d5864c8acbfab8607a5c24cd5de84 100644 (file)
@@ -565,6 +565,8 @@ int FileAppendData(FileContainer *ffc, const uint8_t *data, uint32_t data_len)
         SCReturnInt(-1);
     }
 
+    ffc->tail->size += data_len;
+
     if (ffc->tail->state != FILE_STATE_OPENED) {
         if (ffc->tail->flags & FILE_NOSTORE) {
             SCReturnInt(-2);
@@ -699,6 +701,7 @@ File *FileOpenFile(FileContainer *ffc, const StreamingBufferConfig *sbcfg,
     FileContainerAdd(ffc, ff);
 
     if (data != NULL) {
+        ff->size += data_len;
         if (AppendData(ff, data, data_len) != 0) {
             ff->state = FILE_STATE_ERROR;
             SCReturnPtr(NULL, "File");
@@ -723,6 +726,7 @@ static int FileCloseFilePtr(File *ff, const uint8_t *data,
     }
 
     if (data != NULL) {
+        ff->size += data_len;
         if (ff->flags & FILE_NOSTORE) {
 #ifdef HAVE_NSS
             /* no storage but hashing */
index e0d154de89ac1c7f735c0f60ab5763a2ee115b0c..6794364eb4484bb0c27eaba6176ff0348c755a3a 100644 (file)
@@ -82,6 +82,7 @@ typedef struct File_ {
     uint64_t content_inspected;     /**< used in pruning if FILE_USE_DETECT
                                      *   flag is set */
     uint64_t content_stored;
+    uint64_t size;
 } File;
 
 typedef struct FileContainer_ {