Fix coverity issues 80/176880/4 accepted/tizen/unified/20180503.080803 submit/tizen/20180503.044425
authorseolheui kim <s414.kim@samsung.com>
Tue, 24 Apr 2018 06:02:59 +0000 (15:02 +0900)
committerseolheui kim <s414.kim@samsung.com>
Tue, 24 Apr 2018 12:13:15 +0000 (21:13 +0900)
- fix to catch exceptions from division by zero
- fix to unchecked return values
- remove logically dead code and unused value

Change-Id: I9b9e9c88fd12034a7a737e871d9626b96a736407
Signed-off-by: seolheui kim <s414.kim@samsung.com>
server/engine/encryption/ecryptfs-engine.cpp
server/ext4-tool.cpp
server/internal-encryption.cpp
server/key-manager/anti-forensics.cpp
server/key-manager/key-generator.cpp

index 9afe2b8a082b5224ebbd294fbc33397dbe6049d4..61538c5205f4b6e5a5a8a62bf5cdd8f7ef30c814 100644 (file)
@@ -197,17 +197,14 @@ off_t getEncryptedSize(const runtime::File &file) {
 }
 
 off_t getDecryptedSize(const runtime::File &file) {
-       off_t originalSize = file.size();
-       off_t result = originalSize;
+       off_t result = file.size();
 
        if (wasEncrypted(file.getPath())) {
-               if (originalSize > 2 * 4096) {
-                       result = originalSize - 2 * 4096;
+               if (result > 2 * 4096) {
+                       result -= (2 * 4096);
                }
        }
 
-       result = originalSize;
-
        //TODO : block size have to not hard-coded.
        //       If there is a better way, the followings have to be changed.
        blksize_t blockSize = 4096;
index 22fde773c07c285e4762d1eb5443904d0965ecdc..2fc1ffe81eb99bb4fa00f9e24de13ea402125eb1 100644 (file)
@@ -42,6 +42,9 @@ unsigned int divCeilSafely(unsigned int a, unsigned int b)
        if (!a)
                return 0;
 
+       if (!b)
+               throw runtime::Exception("Cannot divide by zero");
+
        return ((a - 1) / b) + 1;
 }
 
index 32f14634e4b84e7735c85dfb9be562d0ab0168de..46f7942db2a8c25ee5ef826d9439987a07c84a77 100644 (file)
@@ -257,7 +257,8 @@ void showProgressUI(const std::string type)
        };
 
        runtime::Process proc("/usr/bin/ode", args);
-       proc.execute();
+       if (proc.execute() == -1)
+               ERROR(SINK, "Failed to execute progress UI");
 }
 
 unsigned int getOptions()
index b49b8ed0f3f87725472a82f5c1bab4efa94d37e6..969ef3e97048ebc95b478a023a70ba5ea1b17011 100644 (file)
@@ -31,7 +31,8 @@ namespace ode {
 
 static void RNG(unsigned char *buf, size_t resultSize)
 {
-       ::RAND_bytes(buf, resultSize);
+       if (::RAND_bytes(buf, resultSize) != 1)
+               throw runtime::Exception("RAND_bytes() failed");
 }
 
 static void XORBlock(const unsigned char *src1, const unsigned char *src2, unsigned char *dst, size_t size)
@@ -47,7 +48,7 @@ static void hashBuf(unsigned char *src, unsigned char *dst, uint32_t iv,
        iv = htonl(iv);
 
        uint32_t digestSize = 168 / 8;  // use SHA1 in default
-       unsigned char buf[digestSize] = {0x00, };
+       unsigned char buf[digestSize] = {0};
 
        SHA_CTX context;
        if (!::SHA1_Init(&context))
index 3809d0fcfd68f35a0a559d18aeb08a8e9e60c065..3c5816f711412f673fee8c3265ea08229e10db70 100644 (file)
@@ -21,6 +21,7 @@
 #include <openssl/sha.h>
 
 #include <klay/filesystem.h>
+#include <klay/exception.h>
 
 #include "../logger.h"
 #include "key-generator.h"
@@ -134,7 +135,8 @@ BinaryData RNG(size_t resultSize)
 {
        BinaryData ret(resultSize);
 
-       ::RAND_bytes(ret.data(), resultSize);
+       if(::RAND_bytes(ret.data(), resultSize) != 1)
+               throw runtime::Exception("RAND_bytes() failed");
 
        return ret;
 }