From: Bartlomiej Grzelewski Date: Thu, 28 Nov 2013 10:15:55 +0000 (+0100) Subject: Fix errors reported by prevent. X-Git-Tag: submit/tizen/20140307.131547~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fdacc97a7eb8e199a8fa434c9c9d6365d2e8ca67;p=platform%2Fcore%2Fsecurity%2Fsecurity-server.git Fix errors reported by prevent. [Issue#] N/A [Bug/Cuase] Error code was not checked. [Solution] N/A [Verification] Build, run tests. Change-Id: I33c2f0b31416a0720d5dcccb7408b7c6efc569fc --- diff --git a/src/server/main/security-server-util.cpp b/src/server/main/security-server-util.cpp index 2641376..d5363b9 100644 --- a/src/server/main/security-server-util.cpp +++ b/src/server/main/security-server-util.cpp @@ -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; } diff --git a/src/server/service/password-file-buffer.cpp b/src/server/service/password-file-buffer.cpp index d52f447..6a3c3d5 100644 --- a/src/server/service/password-file-buffer.cpp +++ b/src/server/service/password-file-buffer.cpp @@ -33,6 +33,7 @@ #include #include +#include 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) diff --git a/src/server/service/password-file.cpp b/src/server/service/password-file.cpp index 1532e3f..0cef500 100644 --- a/src/server/service/password-file.cpp +++ b/src/server/service/password-file.cpp @@ -38,6 +38,7 @@ #include #include +#include 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