From 643371aa2fec599af05e9081612daa29fdb606eb Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 10 Sep 2020 16:28:25 +0300 Subject: [PATCH] Check message reply header in updates. GitOrigin-RevId: bb71f4cf73f104b6d2f9da18305007336b9397bf --- td/telegram/UpdatesManager.cpp | 29 ++++++++++++++++++++++------- td/telegram/UpdatesManager.h | 3 +++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index e10909ff6..884689b47 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -393,20 +393,34 @@ bool UpdatesManager::is_acceptable_message_entities( return true; } +bool UpdatesManager::is_acceptable_message_reply_header( + const telegram_api::object_ptr &header) const { + if (header == nullptr) { + return true; + } + + if (header->reply_to_peer_id_ != nullptr) { + DialogId dialog_id(header->reply_to_peer_id_); + if (!is_acceptable_dialog(dialog_id)) { + return false; + } + } + return true; +} + bool UpdatesManager::is_acceptable_message_forward_header( const telegram_api::object_ptr &header) const { if (header == nullptr) { return true; } - auto flags = header->flags_; - if (flags & telegram_api::messageFwdHeader::FROM_ID_MASK) { + if (header->from_id_ != nullptr) { DialogId dialog_id(header->from_id_); if (!is_acceptable_dialog(dialog_id)) { return false; } } - if (flags & telegram_api::messageFwdHeader::SAVED_FROM_PEER_MASK) { + if (header->saved_from_peer_ != nullptr) { DialogId dialog_id(header->saved_from_peer_); if (!is_acceptable_dialog(dialog_id)) { return false; @@ -428,12 +442,13 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_ if (!is_acceptable_dialog(DialogId(message->peer_id_))) { return false; } - if (message->flags_ & MessagesManager::MESSAGE_FLAG_HAS_FROM_ID) { - if (!is_acceptable_dialog(DialogId(message->from_id_))) { - return false; - } + if (message->from_id_ != nullptr && !is_acceptable_dialog(DialogId(message->from_id_))) { + return false; } + if (!is_acceptable_message_reply_header(message->reply_to_)) { + return false; + } if (!is_acceptable_message_forward_header(message->fwd_from_)) { return false; } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 45c4978e3..8dab6c4e9 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -190,6 +190,9 @@ class UpdatesManager : public Actor { bool is_acceptable_message_entities(const vector> &message_entities) const; + bool is_acceptable_message_reply_header( + const telegram_api::object_ptr &header) const; + bool is_acceptable_message_forward_header( const telegram_api::object_ptr &header) const;