From 78c7723217fec10a7d23db8d0fe532fb4e3d04b9 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 17 Apr 2018 13:33:14 +0900 Subject: [PATCH 01/16] Check stub appid by using gdbus connection - To detect fake stub, checking appid is needed at the proxy side Change-Id: I3aa4ed676b1ead08948f7159111694374797948c Signed-off-by: Junghoon Park --- src/fdbroker-internal.cc | 15 +++++++++++++++ src/fdbroker-internal.h | 1 + src/proxy-internal.cc | 7 +++++++ src/proxy-internal.h | 1 + 4 files changed, 24 insertions(+) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index ba991c6..edbd33f 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -514,6 +514,21 @@ void FdBroker::OnNameAppeared(GDBusConnection *connection, const gchar *name_owner, gpointer user_data) { FdBroker* broker = static_cast(user_data); + int pid = broker->GetSenderPid(connection, name_owner); + char owner_appid[255] = { 0, }; + + if (aul_app_get_appid_bypid(pid, owner_appid, sizeof(owner_appid)) < 0) { + LOGE("aul_app_get_appid_bypid failed %d", pid); + broker->watcher_->OnPortRejected(owner_appid); + return; + } + + if (broker->watch_appid_ != owner_appid) { + LOGE("invalid appid %s", owner_appid); + broker->watcher_->OnPortRejected(owner_appid); + return; + } + broker->watcher_->OnPortAppeared(broker->watch_appid_, broker->watch_port_name_); } diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index d844064..9237118 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -45,6 +45,7 @@ class FdBroker { const std::string& port_name) = 0; virtual void OnPortVanished(const std::string& appid, const std::string& port_name) = 0; + virtual void OnPortRejected(const std::string& appid) = 0; }; FdBroker(bool mock = false) : mock_(mock) {} diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index b08074c..93a212e 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -113,6 +113,13 @@ int Proxy::Watch(int fd) { return 0; } +void Proxy::OnPortRejected(const std::string& appid) { + if (listener_ == nullptr) + return; + listener_->OnRejected(appid); + listener_ = nullptr; +} + void Proxy::OnPortAppeared(const std::string& appid, const std::string& port_name) { LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 2cad82c..3721371 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -63,6 +63,7 @@ class Proxy : public FdBroker::IEventWatcher { const std::string& port_name) override; void OnPortVanished(const std::string& appid, const std::string& port_name) override; + void OnPortRejected(const std::string& appid) override; private: std::string port_name_; -- 2.7.4 From 6bd6025ad1e2fcbfccc62529b7ecd5ad73c7f29b Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 17 Apr 2018 15:50:24 +0900 Subject: [PATCH 02/16] Release version 1.0.6 Changes: - Check stub appid by using gdbus connection Change-Id: I68a6bca6fa1150d030ef70c4a19a60ceab04cc28 Signed-off-by: Junghoon Park --- 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 a738f19..7537110 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.5 +Version: 1.0.6 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 1977d5bf7a092aabe45afc24c9b3c9724f48e792 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 20 Apr 2018 10:07:24 +0900 Subject: [PATCH 03/16] Comply with google coding rule - Except for some header files regarding c API Change-Id: I6acc664c093de3d257dad34c78a30f1dccc977ef Signed-off-by: Junghoon Park --- doc/rpc-port_doc.h | 6 +++--- src/ac-internal.cc | 22 ++++++++++++++-------- src/ac-internal.h | 9 +++++---- src/fdbroker-internal.cc | 22 +++++++++++++--------- src/fdbroker-internal.h | 7 ++++--- src/parcel-internal.cc | 2 +- src/parcel-internal.h | 2 +- src/proxy-internal.cc | 8 ++++---- src/proxy-internal.h | 4 ++-- src/rpc-port-parcel.cc | 1 - src/rpc-port.cc | 15 ++++++++------- src/stub-internal.cc | 15 ++++++++------- src/stub-internal.h | 4 ++-- tools/check-coding-style | 28 ++++++++++++++++++++++++++++ unit_tests/src/main.cc | 2 +- unit_tests/src/rpc_port_parcel_test.cc | 5 ++--- unit_tests/src/rpc_port_test.cc | 2 -- 17 files changed, 96 insertions(+), 58 deletions(-) create mode 100755 tools/check-coding-style diff --git a/doc/rpc-port_doc.h b/doc/rpc-port_doc.h index a035269..aeb4e5f 100644 --- a/doc/rpc-port_doc.h +++ b/doc/rpc-port_doc.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __RPC_PORT_DOC_H__ -#define __RPC_PORT_DOC_H__ +#ifndef DOC_RPC_PORT_DOC_H_ +#define DOC_RPC_PORT_DOC_H_ /** @@ -42,4 +42,4 @@ */ -#endif /* __RPC_PORT_DOC_H__ */ +#endif // DOC_RPC_PORT_DOC_H_ diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 97f47af..f2e728b 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -45,7 +45,7 @@ void AccessController::SetTrusted(const bool trusted) { trusted_ = trusted; } -int AccessController::CheckPrivilege(Cynara& c) { +int AccessController::CheckPrivilege(const Cynara& c) { for (auto& privilege : privileges_) { if (c.Check(privilege) != 0) { return -1; @@ -66,13 +66,15 @@ int AccessController::CheckTrusted(const char* sender_appid) { LOGD("CheckCertificate : %s :: %s", appid_.c_str(), sender_appid); pkgmgrinfo_cert_compare_result_type_e res; - int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid_.c_str(), sender_appid, getuid(), &res); + int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid_.c_str(), + sender_appid, getuid(), &res); if (ret < 0) { LOGE("CheckCertificate() Failed"); return -1; } if (res != PMINFO_CERT_COMPARE_MATCH) { - LOGE("CheckCertificate() Failed : MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); + LOGE("CheckCertificate() Failed : " \ + "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); return -1; } @@ -123,7 +125,8 @@ AccessController::Cynara::~Cynara() { cynara_finish(cynara_); } -int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, const char* sender) { +int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, + const char* sender) { int ret; if (client_) { @@ -136,13 +139,15 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, co user_ = nullptr; } - ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user_); + 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; } - ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client_); + ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, + &client_); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret); return -1; @@ -152,9 +157,10 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, co return 0; } -int AccessController::Cynara::Check(const std::string& privilege) { +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_, client_, "", user_, privilege.c_str()) != + CYNARA_API_ACCESS_ALLOWED) { LOGD("cynara_check() is not allowed : %s", privilege.c_str()); return -1; } diff --git a/src/ac-internal.h b/src/ac-internal.h index 9a9ae63..d11d33b 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -31,12 +31,13 @@ namespace internal { class AccessController { public: - AccessController(bool trusted = false) : trusted_(trusted) {} + explicit AccessController(bool trusted = false) : trusted_(trusted) {} virtual ~AccessController(); void AddPrivilege(const std::string& privilege); void SetTrusted(const bool trusted); - int Check(GDBusConnection *connection, const char *sender, const char* sender_appid); + int Check(GDBusConnection *connection, const char *sender, + const char* sender_appid); private: class Cynara { @@ -45,7 +46,7 @@ class AccessController { ~Cynara(); int FetchCredsFromDBus(GDBusConnection *connection, const char *sender); - int Check(const std::string& privilege); + int Check(const std::string& privilege) const; private: cynara *cynara_; @@ -55,7 +56,7 @@ class AccessController { int SetCache(const std::string& sender); int CheckTrusted(const char *sender_appid); - int CheckPrivilege(Cynara& c); + int CheckPrivilege(const Cynara& c); private: std::vector privileges_; diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index edbd33f..f8de05b 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -261,9 +261,9 @@ int FdBroker::Send(const std::string& target_appid, } g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); - reply = g_dbus_connection_send_message_with_reply_sync(DBusConnectionManager::GetInst().GetConnection(), - msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, - nullptr, nullptr, &err); + reply = g_dbus_connection_send_message_with_reply_sync( + DBusConnectionManager::GetInst().GetConnection(), + msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, nullptr, nullptr, &err); if (reply == nullptr) { LOGE("No reply. error = %s", err->message); g_error_free(err); @@ -284,7 +284,7 @@ int FdBroker::Send(const std::string& target_appid, LOGE("Access Denied[sender_appid : %s]", sender_appid); g_object_unref(msg); g_object_unref(reply); - return -1; + return -1; } LOGD("[Reply : %d]", ret); @@ -329,8 +329,10 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn, int sender_pid; sender_pid = broker->GetSenderPid(conn, sender); - if (aul_app_get_appid_bypid(sender_pid, sender_appid, sizeof(sender_appid)) < 0) { - g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); + if (aul_app_get_appid_bypid(sender_pid, sender_appid, + sizeof(sender_appid)) < 0) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", ret)); return; } @@ -352,7 +354,8 @@ int FdBroker::GetOwnerId(const std::string& interface_name) { DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "RequestName", - g_variant_new("(su)", interface_name.c_str(), G_BUS_NAME_OWNER_FLAGS_NONE), + g_variant_new("(su)", interface_name.c_str(), + G_BUS_NAME_OWNER_FLAGS_NONE), G_VARIANT_TYPE("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, @@ -390,8 +393,9 @@ int FdBroker::GetSenderPid(GDBusConnection *connection, const gchar *sender) { GVariant *body; int pid = 0; - msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetConnectionUnixProcessID"); + msg = g_dbus_message_new_method_call("org.freedesktop.DBus", + "/org/freedesktop/DBus", "org.freedesktop.DBus", + "GetConnectionUnixProcessID"); if (!msg) { LOGE("Can't allocate new method call"); goto out; diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index 9237118..3dd43d6 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -48,7 +48,7 @@ class FdBroker { virtual void OnPortRejected(const std::string& appid) = 0; }; - FdBroker(bool mock = false) : mock_(mock) {} + explicit FdBroker(bool mock = false) : mock_(mock) {} ~FdBroker(); static void Dispose() { @@ -111,7 +111,7 @@ class FdBroker { RECEIVER = 1 }; - SocketPair(bool mock = false); + explicit SocketPair(bool mock = false); ~SocketPair(); int Request(); @@ -147,7 +147,8 @@ class FdBroker { int GetOwnerId(const std::string& interface_name); int GetSenderPid(GDBusConnection *connection, const gchar *sender); int RegisterDbusInterface(const std::string& port_name); - void ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation); + void ReceiveMessage(const char* sender_appid, + GDBusMethodInvocation* invocation); std::string GetInterfaceName(const std::string& target_appid, const std::string& port_name); static void OnNameAppeared(GDBusConnection *connection, diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index e09b614..e568f90 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -128,4 +128,4 @@ const std::vector& Parcel::GetRaw() { return data_; } -} // namespace rpc_port \ No newline at end of file +} // namespace rpc_port diff --git a/src/parcel-internal.h b/src/parcel-internal.h index c729a49..6fc314a 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -78,4 +78,4 @@ class Parcel { } // namespace rpc_port -#endif // PARCEL_INTERNAL_H_ \ No newline at end of file +#endif // PARCEL_INTERNAL_H_ diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 93a212e..84038eb 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -98,9 +98,9 @@ int Proxy::Watch(int fd) { return -1; } - src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_IN), - OnDataReceived, this); + src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_IN), + OnDataReceived, this); if (src_ == 0) { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); @@ -135,7 +135,7 @@ void Proxy::OnPortAppeared(const std::string& appid, } port_.reset(new Port(fd, port_name)); - listener_->OnConnected(appid, *port_); + listener_->OnConnected(appid, port_.get()); Watch(fd); } diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 3721371..876bc43 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -32,12 +32,12 @@ namespace internal { class Proxy : public FdBroker::IEventWatcher { public: - Proxy(bool mock = false); + explicit Proxy(bool mock = false); virtual ~Proxy(); class IEventListener { public: - virtual void OnConnected(const std::string& endpoint, Port& port) = 0; + virtual void OnConnected(const std::string& endpoint, Port* port) = 0; virtual void OnDisconnected(const std::string& endpoint) = 0; virtual void OnRejected(const std::string& endpoint) = 0; virtual void OnReceived(const std::string& endpoint) = 0; diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 5ede077..8888579 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -227,7 +227,6 @@ RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h, } RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) { - if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; diff --git a/src/rpc-port.cc b/src/rpc-port.cc index bc56034..958e378 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -42,7 +42,7 @@ class Event { class ProxyExt : public Proxy, public Proxy::IEventListener { public: - ProxyExt(bool mock = false) : Proxy(mock) {} + explicit ProxyExt(bool mock = false) : Proxy(mock) {} virtual ~ProxyExt() = default; void AddConnectedEventListener(rpc_port_proxy_connected_event_cb cb, @@ -69,9 +69,9 @@ class ProxyExt : public Proxy, public Proxy::IEventListener { new Event(cb, user_data)); } - void OnConnected(const std::string& endpoint, Port& port) override { + void OnConnected(const std::string& endpoint, Port* port) override { for (auto& ev : connected_events_) { - ev->cb_(endpoint.c_str(), GetPortName().c_str(), &port, + ev->cb_(endpoint.c_str(), GetPortName().c_str(), port, ev->user_data_); } } @@ -112,11 +112,12 @@ class ProxyExt : public Proxy, public Proxy::IEventListener { class StubExt : public Stub, public Stub::IEventListener { public: - StubExt(const std::string& port, bool mock = false) : Stub(port, mock) {} + explicit StubExt(const std::string& port, bool mock = false) + : Stub(port, mock) {} virtual ~StubExt() = default; void AddConnectedEventListener(rpc_port_stub_connected_event_cb cb, - void* user_data) { + void* user_data) { connected_events_.emplace_back( new Event(cb, user_data)); } @@ -148,9 +149,9 @@ class StubExt : public Stub, public Stub::IEventListener { } int OnReceived(const std::string& sender, - const std::string& instance, Port& port) override { + const std::string& instance, Port* port) override { for (auto& ev : received_events_) { - int ret = ev->cb_(sender.c_str(), instance.c_str(), &port, + int ret = ev->cb_(sender.c_str(), instance.c_str(), port, ev->user_data_); if (ret != 0) return -1; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index cbd09ab..a20d125 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -79,7 +79,8 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, return FALSE; } - int ret = stub->listener_->OnReceived(p->GetId(), p->GetInstance(), *p); + int ret = stub->listener_->OnReceived(p->GetId(), p->GetInstance(), + p.get()); if (ret != 0) { LOGW("Invalid protocol"); @@ -155,9 +156,9 @@ int Stub::AcceptedPort::Watch() { return -1; } - disconn_src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), - Stub::OnSocketDisconnected, parent_); + disconn_src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), + Stub::OnSocketDisconnected, parent_); if (disconn_src_ == 0) { LOGE("fail to add watch on socket"); g_io_channel_unref(gioc_); @@ -165,9 +166,9 @@ int Stub::AcceptedPort::Watch() { return -1; } - src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_IN), - Stub::OnDataReceived, parent_); + src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_IN), + Stub::OnDataReceived, parent_); if (src_ == 0) { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); diff --git a/src/stub-internal.h b/src/stub-internal.h index ba66bfe..8883805 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -40,10 +40,10 @@ class Stub : private FdBroker::IEventListener { virtual void OnDisconnected(const std::string& sender, const std::string& instance) = 0; virtual int OnReceived(const std::string& sender, - const std::string& instance, Port& port) = 0; + const std::string& instance, Port* port) = 0; }; - Stub(const std::string& port_name, bool mock = false); + explicit Stub(const std::string& port_name, bool mock = false); virtual ~Stub(); int Listen(IEventListener* ev); diff --git a/tools/check-coding-style b/tools/check-coding-style new file mode 100755 index 0000000..fd60481 --- /dev/null +++ b/tools/check-coding-style @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +if [ ! `which cpplint.py` ]; then + echo -e "\nPlease make sure cpplint.py is in your PATH. It is part of depot_tools inside Chromium repository." + exit 1 +fi + +OLDPWD=$PWD +BASE=`dirname $0` +cd $BASE/.. + +# filters +FILTERS="-readability/streams,-build/c++11" + +cpplint.py --root=src --filter="$FILTERS" $(find . \( -name '*.h' -o -name '*.cc' \) ) +RET=$? + +JS_RET_VAL=$? +cd $OLDPWD + +if [ "x$RET" == "x0" ]; then + exit 0 +else + exit 1 +fi diff --git a/unit_tests/src/main.cc b/unit_tests/src/main.cc index 52756d2..fcdb392 100644 --- a/unit_tests/src/main.cc +++ b/unit_tests/src/main.cc @@ -17,7 +17,7 @@ #include #include -int main(int argc, char** argv){ +int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/unit_tests/src/rpc_port_parcel_test.cc b/unit_tests/src/rpc_port_parcel_test.cc index fba0b95..8e89d22 100644 --- a/unit_tests/src/rpc_port_parcel_test.cc +++ b/unit_tests/src/rpc_port_parcel_test.cc @@ -22,13 +22,12 @@ #include "rpc-port-parcel.h" -using namespace std; using ::testing::AtLeast; namespace { class CStringHolder { public: - CStringHolder(char* ptr) noexcept + explicit CStringHolder(char* ptr) noexcept : ptr_(ptr) {} ~CStringHolder() { if (ptr_) @@ -42,7 +41,7 @@ class CStringHolder { private: char* ptr_; }; -} +} // namespace class ParcelTest : public ::testing::Test { public: diff --git a/unit_tests/src/rpc_port_test.cc b/unit_tests/src/rpc_port_test.cc index 5d8686e..11d6eaf 100644 --- a/unit_tests/src/rpc_port_test.cc +++ b/unit_tests/src/rpc_port_test.cc @@ -23,7 +23,6 @@ #include "rpc-port-internal.h" -using namespace std; using ::testing::AtLeast; class RpcPortBase : public ::testing::Test { @@ -84,7 +83,6 @@ class RpcPortBase : public ::testing::Test { private: static GMainLoop* mainloop_; - }; GMainLoop* RpcPortBase::mainloop_ = nullptr; -- 2.7.4 From 6456416df3d4b73f4fdcf1d532ad46ff3a9bd56e Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 30 Apr 2018 11:27:24 +0900 Subject: [PATCH 04/16] Fix exception safety issue Change-Id: I1bde5ae4e604dc38165ce98105759154be00a2ac Signed-off-by: Junghoon Park --- unit_tests/src/rpc_port_parcel_test.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/unit_tests/src/rpc_port_parcel_test.cc b/unit_tests/src/rpc_port_parcel_test.cc index 8e89d22..1057292 100644 --- a/unit_tests/src/rpc_port_parcel_test.cc +++ b/unit_tests/src/rpc_port_parcel_test.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -198,24 +199,23 @@ TEST_F(ParcelTest, read_write_bundle) { bundle* b = bundle_create(); ASSERT_NE(b, nullptr); - int ret = bundle_add_str(b, "Test", "Value"); + auto bp = std::unique_ptr(b, bundle_free); + + int ret = bundle_add_str(bp.get(), "Test", "Value"); ASSERT_EQ(ret, BUNDLE_ERROR_NONE); - ret = rpc_port_parcel_write_bundle(handle_, b); + ret = rpc_port_parcel_write_bundle(handle_, bp.get()); ASSERT_EQ(ret, 0); - bundle_free(b); b = nullptr; - ret = rpc_port_parcel_read_bundle(handle_, &b); ASSERT_EQ(ret, 0); + bp = std::unique_ptr(b, bundle_free); char* str; - ret = bundle_get_str(b, "Test", &str); + ret = bundle_get_str(bp.get(), "Test", &str); ASSERT_EQ(ret, BUNDLE_ERROR_NONE); ASSERT_STREQ("Value", str); - - bundle_free(b); } TEST_F(ParcelTest, read_write_array_count) { -- 2.7.4 From 047f60ade1953a5b529941e39b57c62a020610d3 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 2 May 2018 14:37:09 +0900 Subject: [PATCH 05/16] Release version 1.0.7 Changes: - Fix exception safety issue - Comply with google coding rule Change-Id: I9dfb6969acd6eeebad426bbc0990663fd17ed2de Signed-off-by: Junghoon Park --- 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 7537110..8e8f0e9 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.6 +Version: 1.0.7 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 5b1a641928e7b5d9a898c6a2804fc6a4034005a3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 4 May 2018 13:43:33 +0900 Subject: [PATCH 06/16] Fix Fdbroker Watch method While calling rejected callback, the developer retriesto connect to stub. This patch removes unnecessary exception handlings about watching gdbus name of stub. Change-Id: If8f8d8a6fcf9e604ec219e2cb5212a4886949fc7 Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index f8de05b..191143b 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -549,9 +549,6 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, const std::string& port_name) { int r; - if (watcher_ != nullptr) - return -1; - if (ev == nullptr) return -1; @@ -577,6 +574,13 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, } std::string interface_name = GetInterfaceName(target_appid, port_name); + + if (watcher_id_ > 0) { + g_bus_unwatch_name(watcher_id_); + LOGD("Retry to watch name. stub %s:%s", + target_appid.c_str(), port_name.c_str()); + } + watcher_id_ = g_bus_watch_name_on_connection( DBusConnectionManager::GetInst().GetConnection(), interface_name.c_str(), -- 2.7.4 From 6a758b09a9572f5ed60e9995f68b91ddc37b2e49 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 4 May 2018 16:09:14 +0900 Subject: [PATCH 07/16] Release version 1.0.8 Changes: - Fix Fdbroker Watch method Change-Id: Ibb63df719888afed42aa8ece7792af420b80d9f6 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 8e8f0e9..1e33d4a 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.7 +Version: 1.0.8 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From dbf210cbc0a16f7f5360f3f4778c6c582e629938 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 8 May 2018 09:19:26 +0900 Subject: [PATCH 08/16] Fix static analysis issue - Uses memset() to initialize a buffer Change-Id: I4a51276c65d8d4075ede631dd4c19c4c16692901 Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 191143b..20d893c 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -18,6 +18,7 @@ #define _GNU_SOURCE #endif +#include #include #include #include @@ -208,9 +209,9 @@ FdBroker::~FdBroker() { std::string FdBroker::GetInterfaceName(const std::string& target_appid, const std::string& port_name) { std::string interface_name = target_appid + "_" + port_name; - char c_buf[interface_name.length() * 2 + 1] = {0}; + char c_buf[interface_name.length() * 2 + 1]; char* temp = &c_buf[0]; - + memset(c_buf, 0, sizeof(c_buf)); for (unsigned int index = 0; index < interface_name.length(); index++) { snprintf(temp, 3, "%02x", interface_name[index]); temp += 2; -- 2.7.4 From eab5bb99e146fcb1b06e62af2c286e57f41b9b35 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 8 May 2018 15:06:11 +0900 Subject: [PATCH 09/16] Release version 1.0.9 Changes: - Fix static analysis issue Change-Id: I0c92b9a012b0dc12dcbc477bf098a42798860cf9 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 1e33d4a..1cce152 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.8 +Version: 1.0.9 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 906018946d40c665abc295e57c0a19bdfb63c86c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 31 May 2018 19:15:00 +0900 Subject: [PATCH 10/16] Change the timeout The timeout value of calling g_dbus_connection_send_message_with_reply_sync() is changed to 5000ms. Change-Id: I495c2ad2c5ae30d3fa047b290191432dae437c9d Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 20d893c..0dce2cf 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -264,7 +264,7 @@ int FdBroker::Send(const std::string& target_appid, g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); reply = g_dbus_connection_send_message_with_reply_sync( DBusConnectionManager::GetInst().GetConnection(), - msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, nullptr, nullptr, &err); + msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 5000, nullptr, nullptr, &err); if (reply == nullptr) { LOGE("No reply. error = %s", err->message); g_error_free(err); -- 2.7.4 From 8895569b3f3f292565d1f16d36e3a0fdc2ce9f3b Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 7 Jun 2018 11:08:06 +0900 Subject: [PATCH 11/16] Adjust timeout value for receiving message Change-Id: I74d6415e33e2da4710298f9981596798b764103d Signed-off-by: Junghoon Park --- src/port-internal.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index 8049fef..a88c9b0 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,7 +35,7 @@ #define LOG_TAG "RPC_PORT" -#define MAX_RETRY_CNT 10 +#define MAX_RETRY_CNT 15 #define SEND_TIMEOUT 500 namespace rpc_port { -- 2.7.4 From 48f3ae802113a958aca4803839c6f5d23354a84e Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 7 Jun 2018 11:10:00 +0900 Subject: [PATCH 12/16] Release version 1.0.10 Changes: - Adjust timeout value for receiving message - Change the timeout Change-Id: Ia48ca34c52b93a96adfe1d96c43770dc4f667fbe Signed-off-by: Junghoon Park --- 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 1cce152..31e6f14 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.9 +Version: 1.0.10 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 61ff69839e4eaa5477004d032f494fee492aef8a Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 11 Jun 2018 11:36:26 +0900 Subject: [PATCH 13/16] Fix overflowing for calling nanosleep() Change-Id: Id12e1e8512410046f9d3fb905ca6b4c363f0622b Signed-off-by: Junghoon Park --- src/port-internal.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index a88c9b0..23432aa 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,7 +35,7 @@ #define LOG_TAG "RPC_PORT" -#define MAX_RETRY_CNT 15 +#define MAX_RETRY_CNT 18 #define SEND_TIMEOUT 500 namespace rpc_port { @@ -74,6 +74,8 @@ int Port::Read(void* buf, unsigned int size) { retry_cnt++; nanosleep(&TRY_SLEEP_TIME, 0); TRY_SLEEP_TIME.tv_nsec *= 2; + if (TRY_SLEEP_TIME.tv_nsec > 999999999) + TRY_SLEEP_TIME.tv_nsec = 999999999; continue; } LOGE("read_socket: ...error fd %d: errno %d\n", fd_, errno); -- 2.7.4 From b5bf78a0ec364515f95f3ad0af1a0030f5fb8308 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 11 Jun 2018 14:31:10 +0900 Subject: [PATCH 14/16] Release version 1.0.11 Changes: - Fix overflowing for calling nanosleep() Change-Id: I1cd6eefc8dbba570bfcd0dfff164f337bca28ddc Signed-off-by: Junghoon Park --- 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 31e6f14..fdb5140 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.10 +Version: 1.0.11 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 828bdffd053327e1b798e1fd2bf37ef41949e02a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 Jun 2018 15:35:56 +0900 Subject: [PATCH 15/16] Fix disconnected event handling - Sets IEventListener to nullptr before calling event callback function. Change-Id: Ibe6c7c1fb9f676167770a2f2cf6d3dae81f58c98 Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 84038eb..593ca7e 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -53,11 +53,12 @@ Proxy::~Proxy() { gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data) { Proxy* proxy = static_cast(data); + IEventListener* listener = proxy->listener_; LOGW("Socket was disconnected"); - proxy->listener_->OnDisconnected(proxy->target_appid_); + proxy->listener_ = nullptr; proxy->disconn_src_ = 0; - + listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -69,8 +70,10 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { LOGW("Socket was disconnected by stub"); - proxy->listener_->OnDisconnected(proxy->target_appid_); + IEventListener* listener = proxy->listener_; + proxy->listener_ = nullptr; proxy->src_ = 0; + listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -116,8 +119,10 @@ int Proxy::Watch(int fd) { void Proxy::OnPortRejected(const std::string& appid) { if (listener_ == nullptr) return; - listener_->OnRejected(appid); + + IEventListener* listener = listener_; listener_ = nullptr; + listener->OnRejected(appid); } void Proxy::OnPortAppeared(const std::string& appid, @@ -129,8 +134,9 @@ void Proxy::OnPortAppeared(const std::string& appid, int fd = fd_broker_.Send(appid, port_name); if (fd <= 0) { - listener_->OnRejected(appid); + IEventListener* listener = listener_; listener_ = nullptr; + listener->OnRejected(appid); return; } -- 2.7.4 From a158358c2943219dd7228635039a7cf2cbbd593e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 Jun 2018 16:57:00 +0900 Subject: [PATCH 16/16] Release version 1.0.12 Changes: - Fix disconnected event handling Change-Id: I362d7d327b9d768a7ab6978fa66dc2ab1cd22ae7 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 fdb5140..3972e70 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.11 +Version: 1.0.12 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4