From 66da2bc97e4dec3ea90f1eaf3f6af8b6e79e3d6d Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Mar 2023 19:17:00 +0300 Subject: [PATCH] Add more input_channel checks. --- td/telegram/ContactsManager.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 114b59d71..54504b8e6 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3844,7 +3844,9 @@ class GetMessageStatsQuery final : public Td::ResultHandler { channel_id_ = channel_id; auto input_channel = td_->contacts_manager_->get_input_channel(channel_id); - CHECK(input_channel != nullptr); + if (input_channel == nullptr) { + return promise_.set_error(Status::Error(400, "Supergroup not found")); + } int32 flags = 0; if (is_dark) { @@ -4007,7 +4009,9 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent TRY_STATUS_PROMISE(promise, G()->close_status()); CHECK(query_ids.size() == 1); auto input_channel = get_input_channel(ChannelId(query_ids[0])); - CHECK(input_channel != nullptr); + if (input_channel == nullptr) { + return promise.set_error(Status::Error(400, "Channel not found")); + } td_->create_handler(std::move(promise))->send(std::move(input_channel)); }); } @@ -12436,11 +12440,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c if (chat_full_ptr->get_id() == telegram_api::chatFull::ID) { auto chat = move_tl_object_as(chat_full_ptr); ChatId chat_id(chat->id_); - if (!chat_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << chat_id; - return promise.set_value(Unit()); - } - Chat *c = get_chat(chat_id); if (c == nullptr) { LOG(ERROR) << "Can't find " << chat_id; @@ -12531,8 +12530,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c CHECK(chat_full_ptr->get_id() == telegram_api::channelFull::ID); auto channel = move_tl_object_as(chat_full_ptr); ChannelId channel_id(channel->id_); - if (!channel_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << channel_id; + auto c = get_channel(channel_id); + if (c == nullptr) { + LOG(ERROR) << "Can't find " << channel_id; return promise.set_value(Unit()); } @@ -12572,12 +12572,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c td_->messages_manager_->on_update_dialog_is_translatable(DialogId(channel_id), !channel->translations_disabled_); - auto c = get_channel(channel_id); - if (c == nullptr) { - LOG(ERROR) << channel_id << " not found"; - return promise.set_value(Unit()); - } - ChannelFull *channel_full = add_channel_full(channel_id); bool have_participant_count = (channel->flags_ & CHANNEL_FULL_FLAG_HAS_PARTICIPANT_COUNT) != 0;