From: Piotr Sawicki
Date: Mon, 10 Jul 2017 11:36:06 +0000 (+0200)
Subject: Prevent from undefined behaviour during destruction of channel users
X-Git-Tag: submit/tizen/20170727.154157~1^2~26
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8f320c72e93c39fed95493ba7bbc55174c0849c;p=platform%2Fcore%2Fsecurity%2Faskuser.git
Prevent from undefined behaviour during destruction of channel users
Change-Id: I07339e74068e066ec61a724b8a1ef6c2dd9670a0
---
diff --git a/src/client/impl/ApiInterfaceImpl.cpp b/src/client/impl/ApiInterfaceImpl.cpp
index 393924e..ec96944 100644
--- a/src/client/impl/ApiInterfaceImpl.cpp
+++ b/src/client/impl/ApiInterfaceImpl.cpp
@@ -68,8 +68,10 @@ namespace Client {
ApiInterfaceImpl::ApiInterfaceImpl(const StatusCallbackClosure &statusClosure)
: m_statusClosure(statusClosure)
-, m_channel(std::move(Protocol::ClientCallbacksPtr(new ClientCallbacks(this))))
{
+ Protocol::ClientCallbacksPtr callbacks(new ClientCallbacks(this));
+ std::unique_ptr channel(new Protocol::ClientChannel(std::move(callbacks)));
+ m_channel = std::move(channel);
}
ApiInterfaceImpl::~ApiInterfaceImpl()
@@ -80,11 +82,12 @@ ApiInterfaceImpl::~ApiInterfaceImpl()
}
m_callbacks.clear();
+ m_channel.reset();
}
int ApiInterfaceImpl::process(int fd, int events)
{
- return m_channel.process(fd, eventsToAskUserMask(events));
+ return m_channel->process(fd, eventsToAskUserMask(events));
}
askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privilege)
@@ -124,7 +127,7 @@ askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privile
RequestId ApiInterfaceImpl::popupRequest(const PopupCallbackClosure &closure,
const std::string &privilege)
{
- Client::RequestId id = static_cast(m_channel.popupRequest(privilege));
+ Client::RequestId id = static_cast(m_channel->popupRequest(privilege));
auto it = m_callbacks.find(id);
if (it != m_callbacks.end()) {
diff --git a/src/client/impl/ApiInterfaceImpl.h b/src/client/impl/ApiInterfaceImpl.h
index 0b45410..2726a76 100644
--- a/src/client/impl/ApiInterfaceImpl.h
+++ b/src/client/impl/ApiInterfaceImpl.h
@@ -55,7 +55,7 @@ public:
private:
StatusCallbackClosure m_statusClosure;
- Protocol::ClientChannel m_channel;
+ std::unique_ptr m_channel;
std::map m_callbacks;
};
diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp
index bf6b670..43300c7 100644
--- a/src/notification-daemon/Logic.cpp
+++ b/src/notification-daemon/Logic.cpp
@@ -166,6 +166,11 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::
addEvent({fd, id}, new EventPopupCheck(&m_popupper, pkgId, privilege));
}
+Logic::~Logic()
+{
+ m_serverChannel.reset();
+}
+
bool Logic::isEventProcessed() {
return m_currentEvent.fd != Protocol::INVALID_FD;
}
diff --git a/src/notification-daemon/Logic.h b/src/notification-daemon/Logic.h
index d05c043..be066cb 100644
--- a/src/notification-daemon/Logic.h
+++ b/src/notification-daemon/Logic.h
@@ -52,7 +52,7 @@ public:
void popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::string &privilege);
- ~Logic() {}
+ ~Logic();
private:
struct EventId {
EventId() : fd(Protocol::INVALID_FD), id(Protocol::INVALID_ID) {}