From b9ff42fddcbfd7a5d419c776c15c44ece42c1f48 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 1 Jul 2019 10:55:03 +0900 Subject: [PATCH 01/16] Change const string& to string - It is better to moving value type in case of adding elements to internal container Change-Id: I31faa20c4fc49b8342183efba8c5809365c8d18b Signed-off-by: Junghoon Park --- src/ac-internal.cc | 4 ++-- src/ac-internal.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 89138ca..a8c0f85 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -37,8 +37,8 @@ namespace internal { AccessController::~AccessController() {} -void AccessController::AddPrivilege(const std::string& privilege) { - privileges_.push_back(privilege); +void AccessController::AddPrivilege(std::string privilege) { + privileges_.push_back(std::move(privilege)); } void AccessController::SetTrusted(const bool trusted) { diff --git a/src/ac-internal.h b/src/ac-internal.h index d11d33b..88bc8be 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -34,7 +34,7 @@ class AccessController { explicit AccessController(bool trusted = false) : trusted_(trusted) {} virtual ~AccessController(); - void AddPrivilege(const std::string& privilege); + void AddPrivilege(std::string privilege); void SetTrusted(const bool trusted); int Check(GDBusConnection *connection, const char *sender, const char* sender_appid); -- 2.7.4 From c0933adc774c48b3a1f291a520859847c3062cfe Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 1 Jul 2019 11:25:04 +0900 Subject: [PATCH 02/16] Use RAII idiom - Change raw pointers to smart pointers Change-Id: Ia81462b077d447763a73cd9584ad160b0c411170 Signed-off-by: Junghoon Park --- src/ac-internal.cc | 51 +++++++++++++++++---------------------------------- src/ac-internal.h | 9 ++++----- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index a8c0f85..f8be409 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -35,8 +35,6 @@ namespace rpc_port { namespace internal { -AccessController::~AccessController() {} - void AccessController::AddPrivilege(std::string privilege) { privileges_.push_back(std::move(privilege)); } @@ -106,61 +104,46 @@ int AccessController::SetCache(const std::string& sender) { return -1; } -AccessController::Cynara::Cynara() { - cynara_ = nullptr; - client_ = nullptr; - user_ = nullptr; +AccessController::Cynara::Cynara() + : cynara_(nullptr, cynara_finish), client_(nullptr, std::free), + user_(nullptr, std::free) { + cynara* cynara_inst = nullptr; - if (cynara_initialize(&cynara_, NULL) != CYNARA_API_SUCCESS) { + if (cynara_initialize(&cynara_inst, NULL) != CYNARA_API_SUCCESS) { LOGE("cynara_initialize() is failed"); + } else { + cynara_.reset(cynara_inst); } } -AccessController::Cynara::~Cynara() { - if (client_) - free(client_); - if (user_) - free(user_); - if (cynara_) - cynara_finish(cynara_); -} - int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, const char* sender) { - int ret; - - if (client_) { - free(client_); - client_ = nullptr; - } - - if (user_) { - free(user_); - user_ = nullptr; - } - - ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, - &user_); + char* user = nullptr; + int ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, + &user); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_user() is failed : %d", ret); return -1; } + user_.reset(user); + char* client = nullptr; ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, - &client_); + &client); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret); return -1; } + client_.reset(client); - LOGD("cred client : %s, cred user : %s", client_, user_); + LOGD("cred client : %s, cred user : %s", client_.get(), user_.get()); return 0; } int AccessController::Cynara::Check(const std::string& privilege) const { LOGD("check privilege %s", privilege.c_str()); - if (cynara_check(cynara_, client_, "", user_, privilege.c_str()) != - CYNARA_API_ACCESS_ALLOWED) { + if (cynara_check(cynara_.get(), client_.get(), "", user_.get(), + privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) { LOGE("cynara_check() is not allowed : %s", privilege.c_str()); return -1; } diff --git a/src/ac-internal.h b/src/ac-internal.h index 88bc8be..174f231 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace rpc_port { namespace internal { @@ -32,7 +33,6 @@ namespace internal { class AccessController { public: explicit AccessController(bool trusted = false) : trusted_(trusted) {} - virtual ~AccessController(); void AddPrivilege(std::string privilege); void SetTrusted(const bool trusted); @@ -43,15 +43,14 @@ class AccessController { class Cynara { public: Cynara(); - ~Cynara(); int FetchCredsFromDBus(GDBusConnection *connection, const char *sender); int Check(const std::string& privilege) const; private: - cynara *cynara_; - char *client_; - char *user_; + std::unique_ptr cynara_; + std::unique_ptr client_; + std::unique_ptr user_; }; int SetCache(const std::string& sender); -- 2.7.4 From 9c8a7134f0bd389effd3033c28e3d400a2a9a569 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 1 Jul 2019 11:47:14 +0900 Subject: [PATCH 03/16] Fix unit tests - Fixes mockup code - Runs the unit tests automatically Change-Id: I154dc6513205e0446336a5cb1fb4e8dba913d691 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 8 ++++++++ packaging/rpc-port.spec | 16 +++++++++++++++- src/fdbroker-internal.cc | 1 + unit_tests/CMakeLists.txt | 3 +++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af6b846..bdc8943 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,4 +56,12 @@ INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/rpc-port FILES_MATCHING PATTERN "*.h") INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION ${LIB_INSTALL_DIR} FILES_MATCHING PATTERN "*.so*") +IF(NOT DEFINED MINIMUM_BUILD) +ENABLE_TESTING() +SET(RPC_PORT_UNITTESTS rpc-port_unittests) +ADD_TEST(NAME ${RPC_PORT_UNITTESTS} COMMAND ${RPC_PORT_UNITTESTS} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unit_tests) + ADD_SUBDIRECTORY(unit_tests) +ADD_DEPENDENCIES(${RPC_PORT_UNITTESTS} rpc-port) +ENDIF(NOT DEFINED MINIMUM_BUILD) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 55877d2..b450277 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -18,6 +18,11 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-creds-gdbus) BuildRequires: pkgconfig(uuid) +%if 0%{?gcov:1} +BuildRequires: lcov +BuildRequires: zip +%endif + Requires(post): /sbin/ldconfig Requires(post): coreutils Requires(postun): /sbin/ldconfig @@ -90,6 +95,15 @@ mkdir -p %{buildroot}%{_datadir}/gcov/obj install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %endif +%check +ctest --output-on-failure %{?_smp_mflags} +%if 0%{?gcov:1} +lcov -c --ignore-errors graph --no-external -q -d . -o rpc-port.info +genhtml rpc-port.info -o rpc-port.out +zip -r rpc-port.zip rpc-port.out rpc-port.info +install -m 0644 rpc-port.zip %{buildroot}%{_datadir}/gcov/ +%endif + %post -p /sbin/ldconfig @@ -121,5 +135,5 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj ################################################# %if 0%{?gcov:1} %files gcov -%{_datadir}/gcov/obj/* +%{_datadir}/gcov/* %endif diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 1993d71..7509e93 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -256,6 +256,7 @@ int FdBroker::Send(const std::string& target_appid, (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER); + watcher_->OnPortConnected(watch_appid_, watch_port_name_); return (*fds)[0]; } diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index a3b19c4..dac0b21 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -19,9 +19,12 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(SOURCES "") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../src) AUX_SOURCE_DIRECTORY(src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../src RPC_PORT_SOURCES) ADD_EXECUTABLE(${PROJECT_NAME} + ${RPC_PORT_SOURCES} ${SOURCES} ) -- 2.7.4 From 2b8fa2d6c0a89c1a91c2d3466291d8b448050029 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 2 Jul 2019 08:19:59 +0900 Subject: [PATCH 04/16] Release version 1.3.13 Changes: - Change const string& to string - Use RAII idiom - Fix unit tests Change-Id: I6d519a50dd8ebca1365481fe916f67e35146f4e7 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index b450277..832e650 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.12 +Version: 1.3.13 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From b95a73c09394aa0d2cf71737f9ee4fa462435564 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 10 Jul 2019 07:58:28 +0900 Subject: [PATCH 05/16] Check IEventWatcher ptr before calling the method This patch add exceptions to check whether the watcher variable is nullptr or not. Change-Id: I846cc3181be4907fc4b6a8178625fe4da34ea45c Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 7509e93..a059c92 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -601,7 +601,10 @@ void FdBroker::OnResultReceived(GObject* source_object, res, &err); if (reply == nullptr) { LOGE("No reply. err(%s)", err ? err->message : "Unknown"); - watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_); + if (watcher) { + watcher->OnPortDisconnected(broker->watch_appid_, + broker->watch_port_name_); + } g_error_free(err); return; } @@ -609,7 +612,10 @@ void FdBroker::OnResultReceived(GObject* source_object, GVariant* reply_body = g_dbus_message_get_body(reply); if (reply_body == nullptr) { LOGE("g_dbus_message_get_body() is failed"); - watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_); + if (watcher) { + watcher->OnPortDisconnected(broker->watch_appid_, + broker->watch_port_name_); + } g_object_unref(reply); return; } @@ -619,11 +625,13 @@ void FdBroker::OnResultReceived(GObject* source_object, g_object_unref(reply); if (ret != 0) { LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str()); - watcher->OnPortRejected(broker->watch_appid_); + if (watcher) + watcher->OnPortRejected(broker->watch_appid_); return; } - watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); + if (watcher) + watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); LOGD("[Reply : %d]", ret); } -- 2.7.4 From c198ecfec3aff95bc3909feaa0bc079804d81969 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 10 Jul 2019 08:17:00 +0900 Subject: [PATCH 06/16] Release version 1.3.14 Changes: - Check IEventWatcher ptr before calling the method Change-Id: Idc1bec9abd6ebab3e57d450058b8fe7353379323 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 832e650..fa30a14 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.13 +Version: 1.3.14 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 4f3db6e235818610f2fb9992ae11e79e52bbdd74 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 Jul 2019 08:49:13 +0900 Subject: [PATCH 07/16] Adjust check section position Some profile doesn't support %check section. It causes the build error issue. To solve the issue, this patch adjusts %check section position. Change-Id: I7f3e0f66691cb8e062d7d1a2ebd12cbbba5bca6b Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index fa30a14..ec1da35 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -85,16 +85,6 @@ mkdir -p gcov-obj find . -name '*.gcno' -exec cp '{}' gcov-obj ';' %endif -%install -rm -rf %{buildroot} - -%make_install - -%if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj -%endif - %check ctest --output-on-failure %{?_smp_mflags} %if 0%{?gcov:1} @@ -104,6 +94,15 @@ zip -r rpc-port.zip rpc-port.out rpc-port.info install -m 0644 rpc-port.zip %{buildroot}%{_datadir}/gcov/ %endif +%install +rm -rf %{buildroot} + +%make_install + +%if 0%{?gcov:1} +mkdir -p %{buildroot}%{_datadir}/gcov/obj +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +%endif %post -p /sbin/ldconfig -- 2.7.4 From 52dcb2cd87793a85f6fd06506d47e6c755641d9b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 Jul 2019 14:02:37 +0900 Subject: [PATCH 08/16] Release version 1.3.15 Changes: - Adjust check section position Change-Id: I346af2b7814834b4fdb70420a19fcbdf6255f297 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index ec1da35..f52ae77 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.14 +Version: 1.3.15 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From c9801b6bee79eb0656e89a7e7e794879a6223365 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 17 Jul 2019 13:36:04 +0900 Subject: [PATCH 09/16] Cancel sending dbus message To prevent calling the callback function after the proxy object is destoyed, the GCancellable object is used. If Send() method is called twice, the previous request will be cancelled. Change-Id: Ibe3d692306864749ee37a0e78cbf7c82de651346 Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 42 ++++++++++++++++++++++++++---------------- src/fdbroker-internal.h | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index a059c92..a8cf58a 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -197,6 +197,12 @@ GUnixFDList* FdBroker::FdList::GetRaw() { } FdBroker::~FdBroker() { + if (cancellable_) { + LOGW("Cancel the send request"); + g_cancellable_cancel(cancellable_); + g_object_unref(cancellable_); + } + if (watcher_id_ > 0) g_bus_unwatch_name(watcher_id_); @@ -273,11 +279,23 @@ int FdBroker::Send(const std::string& target_appid, return -1; } + if (cancellable_) { + g_cancellable_cancel(cancellable_); + g_object_unref(cancellable_); + } + + cancellable_ = g_cancellable_new(); + if (!cancellable_) { + LOGE("Failed to create GCancellable"); + g_object_unref(msg); + return -1; + } + g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); g_dbus_connection_send_message_with_reply( DBusConnectionManager::GetInst().GetConnection(), msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, - 5000, NULL, NULL, OnResultReceived, this); + 5000, NULL, cancellable_, OnResultReceived, this); g_object_unref(msg); (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); @@ -593,29 +611,23 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, void FdBroker::OnResultReceived(GObject* source_object, GAsyncResult* res, gpointer user_data) { - FdBroker* broker = static_cast(user_data); - IEventWatcher* watcher = broker->watcher_; GDBusConnection* conn = reinterpret_cast(source_object); - GError *err = nullptr; + GError* err = nullptr; GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn, res, &err); if (reply == nullptr) { LOGE("No reply. err(%s)", err ? err->message : "Unknown"); - if (watcher) { - watcher->OnPortDisconnected(broker->watch_appid_, - broker->watch_port_name_); - } g_error_free(err); return; } + FdBroker* broker = static_cast(user_data); + IEventWatcher* watcher = broker->watcher_; + GVariant* reply_body = g_dbus_message_get_body(reply); if (reply_body == nullptr) { LOGE("g_dbus_message_get_body() is failed"); - if (watcher) { - watcher->OnPortDisconnected(broker->watch_appid_, - broker->watch_port_name_); - } + watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_); g_object_unref(reply); return; } @@ -625,13 +637,11 @@ void FdBroker::OnResultReceived(GObject* source_object, g_object_unref(reply); if (ret != 0) { LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str()); - if (watcher) - watcher->OnPortRejected(broker->watch_appid_); + watcher->OnPortRejected(broker->watch_appid_); return; } - if (watcher) - watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); + watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); LOGD("[Reply : %d]", ret); } diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index cfd5bbd..aac7584 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -176,6 +176,7 @@ class FdBroker { guint watcher_id_ = 0; std::string watch_appid_; std::string watch_port_name_; + GCancellable* cancellable_ = nullptr; }; } // namespace internal -- 2.7.4 From ffcc0911b2ad4da548a18574d487dea92be1fda7 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 18 Jul 2019 07:21:17 +0900 Subject: [PATCH 10/16] Release version 1.3.16 Changes: - Cancel sending dbus message Change-Id: I5ec86f8eec9c3b54c92e260c5ebfed731ec02513 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index f52ae77..4d3bb69 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.15 +Version: 1.3.16 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 6212af446ce1852de8abbf1984c44fb851adaf49 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 22 Jul 2019 15:46:22 +0900 Subject: [PATCH 11/16] Declare Cynara Destructor If a class has no user-declared destructor, a destructor is implicitly declared as defaulted. An implicitly-declared destructor is an inline public member of its class. Inline definition is equal to inlining and it cause build warning. A function defined within a class definition is an inline function. Problem(Warning): - /home/abuild/rpmbuild/BUILD/rpc-port-1.3.16/src/ac-internal.h:43:9: warning: inlining failed in call to 'rpc_port::internal::AccessController::Cynara::~Cynara() noexcept': call is unlikely and code size would grow [-Winline] Change-Id: I6dc55fb7648da8e41261b53d6f4d2ed472f1292c Signed-off-by: Hwankyu Jhun --- src/ac-internal.cc | 2 ++ src/ac-internal.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index f8be409..ec3d936 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -116,6 +116,8 @@ AccessController::Cynara::Cynara() } } +AccessController::Cynara::~Cynara() = default; + int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, const char* sender) { char* user = nullptr; diff --git a/src/ac-internal.h b/src/ac-internal.h index 174f231..cb3b674 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -43,6 +43,7 @@ class AccessController { class Cynara { public: Cynara(); + ~Cynara(); int FetchCredsFromDBus(GDBusConnection *connection, const char *sender); int Check(const std::string& privilege) const; -- 2.7.4 From 2a6c399d39bf198b3ec2d2e167b8d5abc85ac781 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 22 Jul 2019 17:37:58 +0900 Subject: [PATCH 12/16] Release version 1.3.17 Changes: - Declare Cynara Destructor Change-Id: I196327ecd88c68ef95edbb70430ebc120bd411f4 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 4d3bb69..4f402a6 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.16 +Version: 1.3.17 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From b6c0dd8e247394ace18fb8aedbf4bd3c9b39c40a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Sun, 11 Aug 2019 01:14:34 +0900 Subject: [PATCH 13/16] Fix log message Change-Id: Ie34bdd3e39ddb990694478bcec1906085e9513c9 Signed-off-by: Hwankyu Jhun --- src/ac-internal.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index ec3d936..2e97a9a 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -71,8 +71,7 @@ int AccessController::CheckTrusted(const char* sender_appid) { return -1; } if (res != PMINFO_CERT_COMPARE_MATCH) { - LOGE("CheckCertificate() Failed : " \ - "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); + LOGE("CheckCertificate() Failed : Certificate Not Matched"); return -1; } -- 2.7.4 From 84469cd7124722c6ea9751f911ba63bbaf8170ef Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Aug 2019 08:39:16 +0900 Subject: [PATCH 14/16] Release version 1.3.18 Changes: - Fix log message Change-Id: I7e43be2bbe73496fd2dfc28b7c52686e2e2889a9 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 4f402a6..4dd156a 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.17 +Version: 1.3.18 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 13c213def812fdc2eaf9941298a9a594feb23afa Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 28 Aug 2019 08:56:12 +0900 Subject: [PATCH 15/16] Prevent invalid memory accress - This patch prevents bad memory access - If you try to read data larger than parcel size, the data read will be empty Change-Id: I7792cb9d36b247bea61c3dfc19e55b44aac7af69 Signed-off-by: Junghoon Park --- src/parcel-internal.cc | 10 ++++++++++ src/parcel-internal.h | 4 +++- src/rpc-port-parcel.cc | 7 ++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index cae8988..6ece0b9 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -99,7 +99,11 @@ double Parcel::ReadDouble() { const char* Parcel::ReadString() { int l = Read(); + if (l <= 0) + return nullptr; const char* str = reinterpret_cast(&data_[reader_]); + if (static_cast(strlen(str) + 1) != l) + return nullptr; reader_ += l; return str; @@ -112,7 +116,11 @@ bool Parcel::ReadBool() { bundle* Parcel::ReadBundle() { int l = Read(); + if (l <= 0) + return nullptr; const bundle_raw* str = reinterpret_cast(&data_[reader_]); + if (static_cast(strlen(reinterpret_cast(str)) + 1) != l) + return nullptr; reader_ += l; bundle* b = bundle_decode(str, l - 1); @@ -133,6 +141,8 @@ void Parcel::Write(const unsigned char* buf, unsigned int size) { } void Parcel::Read(unsigned char* buf, unsigned int size) { + if (reader_ + size > data_.size()) + return; std::copy(&data_[reader_], &data_[reader_] + size, buf); reader_ += size; } diff --git a/src/parcel-internal.h b/src/parcel-internal.h index 3b491d0..ac2290a 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -65,9 +65,11 @@ class Parcel { template T Read() { - T d; + T d = 0; unsigned char* p = reinterpret_cast(&d); + if (reader_ + sizeof(T) > data_.size()) + return d; std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p); reader_ += sizeof(T); return d; diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 307808a..f49d9e2 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -297,8 +297,8 @@ RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) { return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); - - *str = strdup(p->ReadString()); + const char* read = p->ReadString(); + *str = read == nullptr ? strdup("") : strdup(read); return RPC_PORT_ERROR_NONE; } @@ -319,8 +319,9 @@ RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) { return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); + bundle* read = p->ReadBundle(); - *b = p->ReadBundle(); + *b = read == nullptr ? bundle_create() : read; return RPC_PORT_ERROR_NONE; } -- 2.7.4 From da1341668f936925b2485108378755526f14b212 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 28 Aug 2019 15:23:54 +0900 Subject: [PATCH 16/16] Release version 1.3.19 Changes: - Prevent invalid memory access Change-Id: Ib31b4d970f383128c67c5c5a5d47452c3497923e Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 4dd156a..2fa9d28 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.18 +Version: 1.3.19 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4