From 3eb593cb61a7a7e2de574a1c54f538f025d90936 Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Thu, 17 Dec 2015 17:21:03 +0000 Subject: protocols: jabber: additional sanity check for incomming pgp encrypted message (xep-0027 is not strict enough), this check is required to avoid incompatibility with some clients with xep-0027 support git-svn-id: http://svn.miranda-ng.org/main/trunk@15885 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_thread.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) mode change 100644 => 100755 protocols/JabberG/src/jabber_thread.cpp (limited to 'protocols/JabberG/src/jabber_thread.cpp') diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp old mode 100644 new mode 100755 index 155bf8f8ad..e723bce2ba --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1202,11 +1202,27 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) if (ptszText == NULL) return; - TCHAR *prolog = _T("-----BEGIN PGP MESSAGE-----\r\n\r\n"); + //XEP-0027 is not strict enough, different clients have different implementations + //additional validation is required + TCHAR *prolog = _T("-----BEGIN PGP MESSAGE-----"); + TCHAR *prolog_newline = _T("\r\n\r\n"); TCHAR *epilog = _T("\r\n-----END PGP MESSAGE-----\r\n"); - size_t len = mir_tstrlen(prolog) + mir_tstrlen(ptszText) + mir_tstrlen(epilog) + 3; - TCHAR *tempstring = (TCHAR*)_alloca(sizeof(TCHAR)*len); - mir_sntprintf(tempstring, len, _T("%s%s%s"), prolog, ptszText, epilog); + + size_t len = 0; + TCHAR *tempstring = nullptr; + if(!_tcsstr(ptszText, prolog)) + { + len = mir_tstrlen(prolog) + mir_tstrlen(prolog_newline) + mir_tstrlen(ptszText) + mir_tstrlen(epilog) + 3; + tempstring = (TCHAR*)_alloca(sizeof(TCHAR)*len); + mir_sntprintf(tempstring, len, _T("%s%s%s%s"), prolog, prolog_newline, ptszText, epilog); + } + else + { + len = mir_tstrlen(ptszText) + 3; + tempstring = (TCHAR*)_alloca(sizeof(TCHAR)*len); + mir_sntprintf(tempstring, len, _T("%s"), ptszText); + } + szMessage = tempstring; } else if (!mir_tstrcmp(ptszXmlns, JABBER_FEAT_DELAY) && msgTime == 0) { -- cgit v1.2.3