From eaa52c28281c997f94897edb52b42a0c6b4d76b8 Mon Sep 17 00:00:00 2001 From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> Date: Wed, 27 Jul 2022 13:00:06 -0300 Subject: [PATCH] vcard: decode escaped chars Since vcard message might arrive with encoded chars. To avoid crashes we properly decode any message and check for the values of interest within a fixed message format. Note: Since https://github.com/pjsip/pjproject/pull/2933, the part=/of= is not un-escaped anymore as the RFC allow escaped character. So this was an old pjproject bug and was working with luck. Change-Id: If454cecab0c7ad6867680306687fb1452dc450cd --- src/libclient/callbackshandler.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libclient/callbackshandler.cpp b/src/libclient/callbackshandler.cpp index 9d7e184c1..a63b8387d 100644 --- a/src/libclient/callbackshandler.cpp +++ b/src/libclient/callbackshandler.cpp @@ -36,6 +36,8 @@ #include <datatransfer_interface.h> #include <QFileInfo> +#include <QUrl> +#include <QRegularExpression> #ifdef ENABLE_LIBWRAP // For the debugMessageReceived connection that queues const std::string refs @@ -528,15 +530,18 @@ CallbacksHandler::slotIncomingMessage(const QString& accountId, for (auto& e : interaction.toStdMap()) { if (e.first.contains("x-ring/ring.profile.vcard")) { - auto pieces0 = e.first.split(";"); - auto pieces1 = pieces0[1].split(","); - auto pieces2 = pieces1[1].split("="); - auto pieces3 = pieces1[2].split("="); + auto decodedHead = QUrl::fromPercentEncoding(e.first.toLatin1()); + QRegularExpression re("x-ring/ring.profile.vcard;id=([A-z0-9]+),part=([0-9]+),of=([0-9]+)"); + auto match = re.match(decodedHead); + + if (!match.hasMatch()) + continue; + Q_EMIT incomingVCardChunk(accountId, callId, from2, - pieces2[1].toInt(), - pieces3[1].toInt(), + match.captured(2).toInt(), + match.captured(3).toInt(), e.second); } else if (e.first.contains( "text/plain")) { // we consider it as an usual message interaction -- GitLab