Fix errors reported by prevent.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 28 Nov 2013 10:15:55 +0000 (11:15 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 6 Feb 2014 16:13:24 +0000 (17:13 +0100)
[Issue#]    N/A
[Bug/Cuase] Error code was not checked.
[Solution]  N/A

[Verification] Build, run tests.

Change-Id: I33c2f0b31416a0720d5dcccb7408b7c6efc569fc

src/server/main/security-server-util.cpp
src/server/service/password-file-buffer.cpp
src/server/service/password-file.cpp

index 2641376..d5363b9 100644 (file)
@@ -60,7 +60,7 @@ int util_smack_label_is_valid(const char *smack_label)
 
     return 1;
 err:
-    LogError("Invalid Smack label: " << smack_label);
+    LogError("Invalid Smack label: " << (smack_label ? smack_label : ""));
     return 0;
 }
 
index d52f447..6a3c3d5 100644 (file)
@@ -33,6 +33,7 @@
 #include <password-exception.h>
 
 #include <fcntl.h>
+#include <string.h>
 
 namespace SecurityServer
 {
@@ -81,7 +82,15 @@ namespace SecurityServer
             Throw(PasswordException::FStreamWriteError);
         }
         file.close();
-        int fd = open(path.c_str(), O_WRONLY | O_APPEND); fsync(fd); close(fd);
+
+        int fd;
+        if (0 <= (fd = open(path.c_str(), O_WRONLY | O_APPEND))) {
+            fsync(fd);
+            close(fd);
+        } else {
+            int err = errno;
+            LogError("Failed to fsync on file: " << path << " strerror: " << strerror(err));
+        }
     }
 
     void PasswordFileBuffer::Load(const std::string &path)
index 1532e3f..0cef500 100644 (file)
@@ -38,6 +38,7 @@
 #include <password-file-buffer.h>
 
 #include <fcntl.h>
+#include <string.h>
 
 const std::string DATA_DIR = "/opt/data/security-server";
 const std::string PASSWORD_FILE = "password.pwd";
@@ -193,7 +194,15 @@ namespace SecurityServer
             Throw(PasswordException::FStreamWriteError);
         }
         attemptFile.close();
-        int fd = open((DATA_DIR + "/" + ATTEMPT_FILE).c_str(), O_WRONLY | O_APPEND); fsync(fd); close(fd);
+
+        int fd;
+        if (0 <= (fd = open((DATA_DIR + "/" + ATTEMPT_FILE).c_str(), O_WRONLY | O_APPEND))) {
+            fsync(fd); // force synchronization system buffers with file
+            close(fd);
+        } else {
+            int err = errno;
+            LogError("Failed to sync attempt file: " << DATA_DIR << "/" << ATTEMPT_FILE << "strerror: " << strerror(err));
+        }
     }
 
     bool PasswordFile::isPasswordActive() const