summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-08-11 13:52:39 +0000
committerRobert Pösel <robyer@seznam.cz>2014-08-11 13:52:39 +0000
commite6b2c1aafe3e877e3a6a90df006887d0b5f59f3d (patch)
tree09f6f8c440f9df9fdeec116ab69f1b245b5ef5e9 /protocols
parentd3e19377a2898c86499b31ca2ea85f8fce643438 (diff)
Facebook: Fix various ptrA issues (potential crashes)
git-svn-id: http://svn.miranda-ng.org/main/trunk@10152 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/chat.cpp3
-rw-r--r--protocols/FacebookRM/src/contacts.cpp27
-rw-r--r--protocols/FacebookRM/src/dialogs.cpp13
-rw-r--r--protocols/FacebookRM/src/proto.cpp24
4 files changed, 45 insertions, 22 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index 82f5368c62..5d2868eecf 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -254,7 +254,8 @@ INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM suppress)
ptrT idT( getTStringA(hContact, "ChatRoomID"));
ptrT nameT( getTStringA(hContact, "Nick"));
- AddChat(idT, nameT);
+ if (idT && nameT)
+ AddChat(idT, nameT);
/* GCSESSION gcw = {sizeof(gcw)};
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index ed8b3cdabe..7905007485 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -109,16 +109,14 @@ MCONTACT FacebookProto::ContactIDToHContact(std::string user_id)
std::string FacebookProto::ThreadIDToContactID(std::string thread_id)
{
- std::string user_id;
-
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (!IsMyContact(hContact))
continue;
ptrA tid(getStringA(hContact, FACEBOOK_KEY_TID));
if (tid && !strcmp(tid, thread_id.c_str())) {
- user_id = ptrA( getStringA(hContact, FACEBOOK_KEY_ID));
- return user_id;
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ return (id ? id : "");
}
}
@@ -132,8 +130,9 @@ std::string FacebookProto::ThreadIDToContactID(std::string thread_id)
data += "&__a=1&__dyn=&__req=&ttstamp=0";
data += "&threads[thread_ids][0]=" + utils::url::encode(thread_id);
+ std::string user_id;
http::response resp = facy.flap(REQUEST_THREAD_INFO, &data);
-
+
if (resp.code == HTTP_CODE_OK) {
CODE_BLOCK_TRY
@@ -455,8 +454,12 @@ void FacebookProto::ApproveContactToServer(void *data)
MCONTACT hContact = *(MCONTACT*)data;
delete data;
+ ptrA id(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ if (!id)
+ return;
+
std::string query = "action=confirm";
- query += "&id=" + std::string(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ query += "&id=" + std::string(id);
query += "&__user=" + facy.self_.user_id;
query += "&fb_dtsg=" + facy.dtsg_;
@@ -489,11 +492,13 @@ void FacebookProto::CancelFriendsRequest(void *data)
MCONTACT hContact = *(MCONTACT*)data;
delete data;
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (!id)
+ return;
+
std::string query = "confirmed=1";
query += "&fb_dtsg=" + facy.dtsg_;
query += "&__user=" + facy.self_.user_id;
-
- ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
query += "&friend=" + std::string(id);
// Cancel (our) friendship request
@@ -525,8 +530,12 @@ void FacebookProto::IgnoreFriendshipRequest(void *data)
MCONTACT hContact = *(MCONTACT*)data;
delete data;
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (!id)
+ return;
+
std::string query = "action=reject";
- query += "&id=" + std::string(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ query += "&id=" + std::string(id);
query += "&__user=" + facy.self_.user_id;
query += "&fb_dtsg=" + facy.dtsg_;
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp
index c3af445c23..4f77b2c53d 100644
--- a/protocols/FacebookRM/src/dialogs.cpp
+++ b/protocols/FacebookRM/src/dialogs.cpp
@@ -152,8 +152,15 @@ void GetSelectedContacts(FacebookProto *proto, MCONTACT hItem, HWND hwndList, st
} else {
if (SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
facebook_user *fu = new facebook_user();
- fu->user_id = ptrA(proto->getStringA(hItem, FACEBOOK_KEY_ID));
- fu->real_name = _T2A(ptrT(proto->getTStringA(hItem, FACEBOOK_KEY_NICK)));
+
+ ptrA userId(proto->getStringA(hItem, FACEBOOK_KEY_ID));
+ if (userId)
+ fu->user_id = userId;
+
+ ptrt realName(proto->getTStringA(hItem, FACEBOOK_KEY_NICK));
+ if (realName)
+ fu->real_name = _T2A(realName);
+
contacts->push_back(fu);
}
}
@@ -265,7 +272,7 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
TCHAR mindMessageT[FACEBOOK_MIND_LIMIT+1];
TCHAR urlT[1024];
- TCHAR placeT[100];
+ TCHAR placeT[100];
GetDlgItemText(hwnd, IDC_MINDMSG, mindMessageT, SIZEOF(mindMessageT));
GetDlgItemText(hwnd, IDC_PLACE, placeT, SIZEOF(placeT));
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 8d9338be37..08afec3fb5 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -314,7 +314,6 @@ int FacebookProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason)
int FacebookProto::GetInfo(MCONTACT hContact, int infoType)
{
ptrA user_id(getStringA(hContact, FACEBOOK_KEY_ID));
-
if (user_id == NULL)
return 1;
@@ -487,8 +486,12 @@ INT_PTR FacebookProto::OnMind(WPARAM wParam, LPARAM lParam)
MCONTACT hContact = MCONTACT(wParam);
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (!id)
+ return 1;
+
wall_data *wall = new wall_data();
- wall->user_id = ptrA(getStringA(hContact, FACEBOOK_KEY_ID));
+ wall->user_id = id;
wall->isPage = false;
if (wall->user_id == facy.self_.user_id) {
wall->title = _tcsdup(TranslateT("Own wall"));
@@ -606,6 +609,8 @@ INT_PTR FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam)
return 1;
ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (!id)
+ return 1;
std::string url = FACEBOOK_URL_PROFILE;
url += facy.self_.user_id;
@@ -622,14 +627,12 @@ INT_PTR FacebookProto::VisitConversation(WPARAM wParam, LPARAM lParam)
if (wParam == 0 || !IsMyContact(hContact, true))
return 1;
- std::string url = FACEBOOK_URL_CONVERSATION;
+ bool isChat = isChatRoom(hContact);
+ ptrA id(getStringA(hContact, isChat ? FACEBOOK_KEY_TID : FACEBOOK_KEY_ID));
+ if (id == NULL)
+ return 1;
- if (isChatRoom(hContact)) {
- url += "conversation-";
- url += ptrA(getStringA(hContact, FACEBOOK_KEY_TID));
- } else {
- url += ptrA(getStringA(hContact, FACEBOOK_KEY_ID));
- }
+ std::string url = FACEBOOK_URL_CONVERSATION + (isChat ? "conversation-" : "") + std::string(id);
OpenUrl(url);
return 0;
@@ -672,6 +675,9 @@ INT_PTR FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
ptrT tname(getTStringA(hContact, FACEBOOK_KEY_NICK));
if (tname == NULL)
tname = getTStringA(hContact, FACEBOOK_KEY_ID);
+
+ if (tname == NULL)
+ return 1;
TCHAR tstr[256];
mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), tname);