Add dir blacklist which are excluded from scanning 69/74169/2
authorKyungwook Tak <k.tak@samsung.com>
Mon, 13 Jun 2016 05:06:20 +0000 (14:06 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Mon, 13 Jun 2016 05:11:30 +0000 (14:11 +0900)
Some files (procfs, sysfs) can occur undefined behavior when file
opened. Like sensor device file, it's blocked when file just opened.

File opening/reading could be differently implemented by engine in lower
layer of csr daemon so we cannot control all of them.

Change-Id: I157e3c21bb8e1c9e3b0afe9fbe65f97ad6eefefb
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/CMakeLists.txt
src/framework/service/cs-logic.cpp
src/framework/service/dir-blacklist.cpp [new file with mode: 0644]
src/framework/service/dir-blacklist.h [new file with mode: 0644]
src/framework/service/file-system.cpp
test/internals/CMakeLists.txt

index be82c63..2c1e139 100755 (executable)
@@ -54,6 +54,7 @@ SET(${TARGET_CSR_SERVER}_SRCS
        framework/service/cs-loader.cpp
        framework/service/wp-loader.cpp
        framework/service/engine-error-converter.cpp
+       framework/service/dir-blacklist.cpp
        framework/ui/askuser.cpp
 
        # question and response codes needed on both of
index c8c55f6..8e73911 100644 (file)
@@ -31,6 +31,7 @@
 #include "service/type-converter.h"
 #include "service/engine-error-converter.h"
 #include "service/core-usage.h"
+#include "service/dir-blacklist.h"
 #include "ui/askuser.h"
 #include <csr-error.h>
 
@@ -376,6 +377,9 @@ RawBuffer CsLogic::scanApp(const CsContext &context, const std::string &pkgPath)
 RawBuffer CsLogic::scanFileWithoutDelta(const CsContext &context,
                                                                                const std::string &filepath, FilePtr &&fileptr)
 {
+       if (isInBlackList(filepath))
+               return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+
        CsEngineContext engineContext(this->m_loader);
        auto &c = engineContext.get();
 
diff --git a/src/framework/service/dir-blacklist.cpp b/src/framework/service/dir-blacklist.cpp
new file mode 100644 (file)
index 0000000..6bb652c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        dir-blacklist.cpp
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       directory blacklist to keep out of scanning
+ */
+#include "service/dir-blacklist.h"
+
+#include <cstring>
+
+namespace {
+
+const size_t DIR_BLACK_LIST_SIZE = 3;
+const char *DIR_BLACK_LIST[DIR_BLACK_LIST_SIZE] = {
+       "/proc",
+       "/sys",
+       "/usr"
+};
+
+} // namespace anonymous
+
+namespace Csr {
+
+bool isInBlackList(const std::string &path)
+{
+       for (size_t i = 0; i < DIR_BLACK_LIST_SIZE; ++i) {
+               const auto &black = DIR_BLACK_LIST[i];
+
+               if (path == black)
+                       return true;
+
+               auto black_size = strlen(black);
+               auto path_size = path.size();
+
+               // path is in black dir
+               if (path_size > black_size && path[black_size] == '/' &&
+                       path.compare(0, black_size, black) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
+}
diff --git a/src/framework/service/dir-blacklist.h b/src/framework/service/dir-blacklist.h
new file mode 100644 (file)
index 0000000..8cc92ab
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        dir-blacklist.h
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       directory blacklist to keep out of scanning
+ */
+#pragma once
+
+#include <string>
+
+namespace Csr {
+
+// param[in] path: canonicalized absolute path of file or directory
+bool isInBlackList(const std::string &path);
+
+}
index 16be24d..6e3c94e 100644 (file)
@@ -32,6 +32,7 @@
 #include "common/exception.h"
 #include "service/app-deleter.h"
 #include "service/fs-utils.h"
+#include "service/dir-blacklist.h"
 
 #include <pkgmgr-info.h>
 
@@ -285,6 +286,9 @@ FilePtr FsVisitor::next()
                } else if (result == nullptr) {
                        DEBUG("End of stream of dir: " << this->m_dirs.front());
                        isDone = true;
+               } else if (isInBlackList(this->m_dirs.front())) {
+                       DEBUG("dir[" << this->m_dirs.front() << "] is in black list.");
+                       isDone = true;
                }
 
                if (isDone) {
index ecf0752..2bfee59 100644 (file)
@@ -50,6 +50,7 @@ SET(${TARGET_CSR_INTERNAL_TEST}_SRCS
        ${CSR_FW_SRC_PATH}/service/cs-loader.cpp
        ${CSR_FW_SRC_PATH}/service/wp-loader.cpp
        ${CSR_FW_SRC_PATH}/service/engine-error-converter.cpp
+       ${CSR_FW_SRC_PATH}/service/dir-blacklist.cpp
        ${CSR_FW_SRC_PATH}/ui/popup/package-info.cpp
 
        test-db.cpp