From fac13ff3a3dd37cf3b1471e7727912019c38c0f8 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 3 Jul 2023 19:30:50 +0300 Subject: [PATCH] Check parsed UserPrivacySettingRule for validness. --- td/telegram/UserPrivacySettingRule.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/td/telegram/UserPrivacySettingRule.h b/td/telegram/UserPrivacySettingRule.h index 970489d32..e3291d32f 100644 --- a/td/telegram/UserPrivacySettingRule.h +++ b/td/telegram/UserPrivacySettingRule.h @@ -53,9 +53,22 @@ class UserPrivacySettingRule { td::parse(type_, parser); if (type_ == Type::AllowUsers || type_ == Type::RestrictUsers) { td::parse(user_ids_, parser); - } - if (type_ == Type::AllowChatParticipants || type_ == Type::RestrictChatParticipants) { + for (auto user_id : user_ids_) { + if (!user_id.is_valid()) { + parser.set_error("Failed to parse user identifiers"); + } + } + } else if (type_ == Type::AllowChatParticipants || type_ == Type::RestrictChatParticipants) { td::parse(dialog_ids_, parser); + for (auto dialog_id : dialog_ids_) { + auto dialog_type = dialog_id.get_type(); + if (!dialog_id.is_valid() || (dialog_type != DialogType::Chat && dialog_type != DialogType::Channel)) { + parser.set_error("Failed to parse chat identifiers"); + } + } + } else if (type_ != Type::AllowContacts && type_ != Type::AllowCloseFriends && type_ != Type::AllowAll && + type_ != Type::RestrictContacts && type_ != Type::RestrictAll) { + parser.set_error("Invalid privacy rule type"); } }