Fix SVACE and C++ issues 27/193827/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 26 Nov 2018 16:16:51 +0000 (17:16 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 3 Dec 2018 14:37:26 +0000 (14:37 +0000)
Change-Id: Idfed338ad6f632556585e5749817bb882cbe0251

src/manager/main/socket-manager.cpp
src/manager/service/access-control.cpp
src/manager/service/access-control.h
src/manager/service/file-system.cpp
src/manager/service/key-provider.cpp
tests/encryption-scheme/scheme-test.cpp

index db3f2a6..60c7c77 100644 (file)
@@ -202,6 +202,7 @@ SocketManager::SocketManager() :
        if (-1 == filefd) {
                LogError("Error in SignalService.GetDescriptor()");
                delete signalService;
+               signalService = nullptr;
        } else {
                auto &desc2 = CreateDefaultReadSocketDescription(filefd, false);
                desc2.service = signalService;
index 0704147..e57539b 100644 (file)
@@ -31,6 +31,10 @@ const uid_t SYSTEM_SVC_MAX_UID = (5000 - 1);
 
 namespace CKM {
 
+AccessControl::AccessControl() : m_ccMode(false)
+{
+}
+
 void AccessControl::updateCCMode()
 {
        /* newMode should be extracted from global property like buxton in product */
index 4488b92..3e50ce3 100644 (file)
@@ -32,6 +32,7 @@ namespace CKM {
 
 class AccessControl {
 public:
+       AccessControl();
        /**
         * return true if client uid is from the system services uid space
         */
index 79f8081..6a70c20 100644 (file)
@@ -187,7 +187,7 @@ int FileSystem::init()
 {
        errno = 0;
 
-       if ((mkdir(RW_DATA_DIR, 0700)) && (errno != EEXIST)) {
+       if ((mkdir(RW_DATA_DIR, S_IRWXU)) && (errno != EEXIST)) {
                int err = errno;
                LogError("Error in mkdir " << RW_DATA_DIR << ". Reason: " << GetErrnoString(
                                         err));
index 95c68af..a1bc1e5 100644 (file)
@@ -69,10 +69,11 @@ void WrappedKeyAndInfoContainer::setKeyInfoKeyLength(const unsigned int length)
 
 void WrappedKeyAndInfoContainer::setKeyInfoClient(const std::string resized_client)
 {
-       strncpy(
-               wrappedKeyAndInfo->keyInfo.client,
-               resized_client.c_str(),
-               MAX_CLIENT_ID_SIZE-1);
+       if (resized_client.size() >= sizeof(wrappedKeyAndInfo->keyInfo.client)) {
+               ThrowErr(Exc::InternalError, "Client name too long");
+       }
+
+       strcpy(wrappedKeyAndInfo->keyInfo.client, resized_client.c_str());
 }
 
 void WrappedKeyAndInfoContainer::setKeyInfoSalt(const unsigned char *salt,
index 66afdbc..d851f42 100644 (file)
@@ -60,6 +60,7 @@ RawBuffer TEST_DATA(TEST_DATA_STR.begin(), TEST_DATA_STR.end());
 const Password TEST_PASS = "custom user password";
 const size_t IV_LEN = 16;
 const size_t CHAIN_LEN = 3;
+const mode_t MODE_0644 = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
 
 enum {
        NO_PASS = 0,
@@ -348,7 +349,7 @@ void restoreFile(const string &filename)
 
        FdPtr sourceFdPtr(&sourceFd);
 
-       int targetFd = TEMP_FAILURE_RETRY(creat(targetPath.c_str(), 0644));
+       int targetFd = TEMP_FAILURE_RETRY(creat(targetPath.c_str(), MODE_0644));
        err = errno;
        BOOST_REQUIRE_MESSAGE(targetFd > 0,
                                                  "Creating " << targetPath << " failed: " << GetErrnoString(err));