Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#15667. Avoid access to attribute cache when it's uninitialized #862

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/chatClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ class Client: public ::mega::MegaGlobalListener,
const std::string& myEmail() const { return mMyEmail; }
uint64_t myIdentity() const { return mMyIdentity; }
UserAttrCache& userAttrCache() const { return *mUserAttrCache; }
bool isUserAttrCacheReady() const { return mUserAttrCache.get(); }

ConnState connState() const { return mConnState; }
bool connected() const { return mConnState == kConnected; }
Expand Down
26 changes: 25 additions & 1 deletion src/megachatapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,14 @@ void MegaChatApiImpl::sendPendingRequests()
}
case MegaChatRequest::TYPE_GET_FIRSTNAME:
{
// if the app requested user attributes too early (ie. init with sid but without cache),
// the cache will not be ready yet. It needs to wait for fetchnodes to complete.
if (!mClient->isUserAttrCacheReady())
{
errorCode = MegaChatError::ERROR_ACCESS;
break;
}

MegaChatHandle uh = request->getUserHandle();
const char* publicHandle = request->getLink();
MegaChatHandle ph = publicHandle ? karere::Id(publicHandle, strlen(publicHandle)).val : MEGACHAT_INVALID_HANDLE;
Expand All @@ -1100,6 +1108,14 @@ void MegaChatApiImpl::sendPendingRequests()
}
case MegaChatRequest::TYPE_GET_LASTNAME:
{
// if the app requested user attributes too early (ie. init with sid but without cache),
// the cache will not be ready yet. It needs to wait for fetchnodes to complete.
if (!mClient->isUserAttrCacheReady())
{
errorCode = MegaChatError::ERROR_ACCESS;
break;
}

MegaChatHandle uh = request->getUserHandle();
const char* publicHandle = request->getLink();
MegaChatHandle ph = publicHandle ? karere::Id(publicHandle, strlen(publicHandle)).val : MEGACHAT_INVALID_HANDLE;
Expand All @@ -1123,8 +1139,15 @@ void MegaChatApiImpl::sendPendingRequests()
}
case MegaChatRequest::TYPE_GET_EMAIL:
{
MegaChatHandle uh = request->getUserHandle();
// if the app requested user attributes too early (ie. init with sid but without cache),
// the cache will not be ready yet. It needs to wait for fetchnodes to complete.
if (!mClient->isUserAttrCacheReady())
{
errorCode = MegaChatError::ERROR_ACCESS;
break;
}

MegaChatHandle uh = request->getUserHandle();
mClient->userAttrCache().getAttr(uh, karere::USER_ATTR_EMAIL)
.then([request, this](Buffer *data)
{
Expand Down Expand Up @@ -1768,6 +1791,7 @@ void MegaChatApiImpl::sendPendingRequests()
});
break;
}

case MegaChatRequest::TYPE_IMPORT_MESSAGES:
{
if (mClient->initState() != karere::Client::kInitHasOfflineSession
Expand Down