diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-07-17 18:55:36 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-07-17 18:55:36 +0300 |
commit | 4ecdb004e81a459ea63ebd7127e1c945df43f9ce (patch) | |
tree | a8ece58a62724c4b088484e0b5c1f44fdbf2f7e1 /src/fs/virtfs | |
parent | 334c1c50dfa57da0b91687e097db295a6a3b699b (diff) | |
download | mv-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.gz mv-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.bz2 mv-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.xz mv-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.zip |
Fix issues detected by coverity.
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r-- | src/fs/virtfs/direntry.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/fsdir.cpp | 12 | ||||
-rw-r--r-- | src/fs/virtfs/fsdirrwops.cpp | 11 | ||||
-rw-r--r-- | src/fs/virtfs/fsentry.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/zipentry.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/zipreader.cpp | 6 |
6 files changed, 30 insertions, 5 deletions
diff --git a/src/fs/virtfs/direntry.h b/src/fs/virtfs/direntry.h index 41d9afc7c..18e700a6a 100644 --- a/src/fs/virtfs/direntry.h +++ b/src/fs/virtfs/direntry.h @@ -38,7 +38,7 @@ struct DirEntry final : public FsEntry A_DELETE_COPY(DirEntry) - ~DirEntry(); + virtual ~DirEntry(); std::string userDir; std::string rootSubDir; diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index 60fc9f977..be980ae65 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -377,6 +377,11 @@ namespace FsDir } #ifdef USE_FILE_FOPEN const long pos = ftell(fd); + if (pos < 0) + { + reportAlways("FsDir::fileLength ftell error."); + return -1; + } fseek(fd, 0, SEEK_END); const long sz = ftell(fd); fseek(fd, pos, SEEK_SET); @@ -483,6 +488,13 @@ namespace FsDir #ifdef USE_FILE_FOPEN fseek(fd, 0, SEEK_END); const long sz = ftell(fd); + if (sz < 0) + { + reportAlways("FsDir::fileLength ftell error."); + if (fd != FILEHDEFAULT) + FILECLOSE(fd); + return nullptr; + } fseek(fd, 0, SEEK_SET); fileSize = static_cast<int>(sz); #else // USE_FILE_FOPEN diff --git a/src/fs/virtfs/fsdirrwops.cpp b/src/fs/virtfs/fsdirrwops.cpp index bef2534fb..b428ed333 100644 --- a/src/fs/virtfs/fsdirrwops.cpp +++ b/src/fs/virtfs/fsdirrwops.cpp @@ -25,6 +25,7 @@ #include "fs/virtfs/file.h" #include "utils/cast.h" +#include "utils/checkutils.h" PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") @@ -86,6 +87,11 @@ namespace FsDir int64_t len = 0; #ifdef USE_FILE_FOPEN const long curpos = ftell(fd); + if (curpos < 0) + { + reportAlways("FsDir::fileLength ftell error."); + return -1; + } fseek(fd, 0, SEEK_END); len = ftell(fd); // fseek(fd, curpos, SEEK_SET); @@ -105,7 +111,10 @@ namespace FsDir if (len == -1) { #ifdef USE_FILE_FOPEN - fseek(fd, curpos, SEEK_SET); + if (fseek(fd, curpos, SEEK_SET) < 0) + { + reportAlways("FsDir::fileLength fseek error."); + } #endif // USE_FILE_FOPEN logger->assertLog( "VirtFs::rwops_seek:Can't find end of file."); diff --git a/src/fs/virtfs/fsentry.h b/src/fs/virtfs/fsentry.h index 81568adb7..09ca136b0 100644 --- a/src/fs/virtfs/fsentry.h +++ b/src/fs/virtfs/fsentry.h @@ -39,7 +39,7 @@ struct FsEntry notfinal A_DELETE_COPY(FsEntry) - ~FsEntry(); + virtual ~FsEntry(); std::string root; diff --git a/src/fs/virtfs/zipentry.h b/src/fs/virtfs/zipentry.h index 3d8a21ced..eaf77889d 100644 --- a/src/fs/virtfs/zipentry.h +++ b/src/fs/virtfs/zipentry.h @@ -40,7 +40,7 @@ struct ZipEntry final : public FsEntry A_DELETE_COPY(ZipEntry) - ~ZipEntry(); + virtual ~ZipEntry(); STD_VECTOR<ZipLocalHeader*> mHeaders; STD_VECTOR<std::string> mDirs; diff --git a/src/fs/virtfs/zipreader.cpp b/src/fs/virtfs/zipreader.cpp index 017686e6b..7f3e48463 100644 --- a/src/fs/virtfs/zipreader.cpp +++ b/src/fs/virtfs/zipreader.cpp @@ -27,6 +27,7 @@ #include "utils/cast.h" #include "utils/checkutils.h" +#include "utils/delete2.h" #include "utils/stringutils.h" #include <zlib.h> @@ -55,7 +56,7 @@ extern const char *dirSeparator; { \ reportAlways("Error reading " msg " in file %s", \ archiveName.c_str()); \ - delete header; \ + delete2(header); \ delete [] buf; \ fclose(arcFile); \ return false; \ @@ -290,7 +291,10 @@ namespace ZipReader const size_t outSize = header->uncompressSize; uint8_t *restrict const out = new uint8_t[outSize]; if (outSize == 0) + { + delete [] in; return out; + } z_stream strm; strm.zalloc = nullptr; |