[Prevent] Handle fread return value.
authorJan Olszak <j.olszak@samsung.com>
Tue, 13 Nov 2012 11:52:23 +0000 (12:52 +0100)
committerJan Olszak <j.olszak@samsung.com>
Fri, 23 Nov 2012 14:20:52 +0000 (15:20 +0100)
[Issue#] Unhandled return value.
[Bug] N/A
[Cause] N/A
[Solution] Logging on error.
[Verification] Build installer

Change-Id: If3d7880115452c86e6bffee7cae8aa691916f2bb

src/jobs/widget_install/task_encrypt_resource.cpp

index 9b0bdb4..2ea97ee 100644 (file)
@@ -27,6 +27,8 @@
 #include <string>
 #include <sys/stat.h>
 #include <fts.h>
+#include <string.h>
+#include <errno.h>
 
 #include <dpl/log/log.h>
 #include <dpl/errno_string.h>
@@ -161,17 +163,24 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
             memset(readBuf, 0, fileSize);
             memset(outEncBuf, 0, blockSize);
 
-            fread(readBuf, sizeof(unsigned char), fileSize, resFp);
-            fclose(resFp);
+            ret = fread(readBuf, sizeof(unsigned char), fileSize, resFp);
+            if (ret!=fileSize){
+                LogError("Failed to read ecryption buffer with error: " << strerror(errno) );
+                fclose(resFp);
+               return;
+            }
 
             m_resEnc->EncryptChunk(readBuf, outEncBuf, fileSize);
 
             FILE* encFp = fopen(encFile.c_str(), "w");
             if (NULL == encFp) {
                 LogError("Failed to open ecryption file");
+                fclose(resFp);
                 return;
             }
             fwrite(outEncBuf, sizeof(unsigned char), blockSize, encFp);
+
+            fclose(resFp);
             fclose(encFp);
 
             LogDebug("Success to encrypt file");