fix crash

Signed-off-by: yanghuiqing <yanghuiqing6@huawei.com>
This commit is contained in:
yanghuiqing 2024-08-29 21:57:37 +08:00
parent a579773458
commit 46c1af5ca8
3 changed files with 26 additions and 0 deletions

View File

@ -19,6 +19,10 @@
#include "iremote_object.h" #include "iremote_object.h"
namespace OHOS { namespace OHOS {
constexpr uint32_t BEFORE_MAGIC = 0x5A5A5A5A;
constexpr uint32_t AFTER_MAGIC = 0xA5A5A5A5;
class PeerHolder { class PeerHolder {
protected: protected:
PeerHolder(const sptr<IRemoteObject> &object); PeerHolder(const sptr<IRemoteObject> &object);
@ -33,7 +37,19 @@ protected:
sptr<IRemoteObject> Remote(); sptr<IRemoteObject> Remote();
private: private:
uint32_t beforeMagic_ = BEFORE_MAGIC;
const sptr<IRemoteObject> remoteObject_; const sptr<IRemoteObject> remoteObject_;
uint32_t afterMagic_ = AFTER_MAGIC;
uint32_t GetBeforeMagic()
{
return beforeMagic_;
}
uint32_t GetAfterMagic()
{
return afterMagic_;
}
}; };
} // namespace OHOS } // namespace OHOS
#endif // OHOS_IPC_PEER_HOLDER_H #endif // OHOS_IPC_PEER_HOLDER_H

View File

@ -15,14 +15,23 @@
#include "peer_holder.h" #include "peer_holder.h"
#include "ipc_debug.h"
#include "iremote_object.h" #include "iremote_object.h"
#include "log_tags.h"
#include "refbase.h" #include "refbase.h"
namespace OHOS { namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_PEER_HOLDER, "PeerHolder" };
PeerHolder::PeerHolder(const sptr<IRemoteObject> &object) : remoteObject_(object) {} PeerHolder::PeerHolder(const sptr<IRemoteObject> &object) : remoteObject_(object) {}
sptr<IRemoteObject> PeerHolder::Remote() sptr<IRemoteObject> PeerHolder::Remote()
{ {
if (GetBeforeMagic() != BEFORE_MAGIC || GetAfterMagic() != AFTER_MAGIC) {
ZLOGE(LOG_LABEL, "remoteObject invalid, beforeMagic:%{public}x afterMagic:%{public}x",
beforeMagic_, afterMagic_);
return nullptr;
}
return remoteObject_; return remoteObject_;
} }
} // namespace OHOS } // namespace OHOS

View File

@ -43,5 +43,6 @@ const unsigned int LOG_ID_RPC_DBINDER_INVOKER = LOG_ID_IPC_BASE | 0x14;
const unsigned int LOG_ID_RPC_REMOTE_LISTENER = LOG_ID_IPC_BASE | 0x15; const unsigned int LOG_ID_RPC_REMOTE_LISTENER = LOG_ID_IPC_BASE | 0x15;
const unsigned int LOG_ID_RPC_DBINDER_CB_STUB = LOG_ID_IPC_BASE | 0x16; const unsigned int LOG_ID_RPC_DBINDER_CB_STUB = LOG_ID_IPC_BASE | 0x16;
const unsigned int LOG_ID_IPC_DBINDER_SOFTBUS_CLIENT = LOG_ID_IPC_BASE | 0x17; const unsigned int LOG_ID_IPC_DBINDER_SOFTBUS_CLIENT = LOG_ID_IPC_BASE | 0x17;
const unsigned int LOG_ID_IPC_PEER_HOLDER = LOG_ID_IPC_BASE | 0x18;
} // namespace OHOS } // namespace OHOS
#endif // OHOS_COMMUNICATION_LOG_TAGS_H #endif // OHOS_COMMUNICATION_LOG_TAGS_H