From: Kyungwook Tak Date: Mon, 13 Jun 2016 05:06:20 +0000 (+0900) Subject: Add dir blacklist which are excluded from scanning X-Git-Tag: accepted/tizen/common/20160614.143943^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F74169%2F2;p=platform%2Fupstream%2Fcsr-framework.git Add dir blacklist which are excluded from scanning 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 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be82c63..2c1e139 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/framework/service/cs-logic.cpp b/src/framework/service/cs-logic.cpp index c8c55f6..8e73911 100644 --- a/src/framework/service/cs-logic.cpp +++ b/src/framework/service/cs-logic.cpp @@ -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 @@ -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 index 0000000..6bb652c --- /dev/null +++ b/src/framework/service/dir-blacklist.cpp @@ -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 + +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 index 0000000..8cc92ab --- /dev/null +++ b/src/framework/service/dir-blacklist.h @@ -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 + +namespace Csr { + +// param[in] path: canonicalized absolute path of file or directory +bool isInBlackList(const std::string &path); + +} diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp index 16be24d..6e3c94e 100644 --- a/src/framework/service/file-system.cpp +++ b/src/framework/service/file-system.cpp @@ -32,6 +32,7 @@ #include "common/exception.h" #include "service/app-deleter.h" #include "service/fs-utils.h" +#include "service/dir-blacklist.h" #include @@ -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) { diff --git a/test/internals/CMakeLists.txt b/test/internals/CMakeLists.txt index ecf0752..2bfee59 100644 --- a/test/internals/CMakeLists.txt +++ b/test/internals/CMakeLists.txt @@ -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