diff --git a/Telegram/SourceFiles/mtproto/session_private.cpp b/Telegram/SourceFiles/mtproto/session_private.cpp index 41c6c57a4d..f7b300a0e9 100644 --- a/Telegram/SourceFiles/mtproto/session_private.cpp +++ b/Telegram/SourceFiles/mtproto/session_private.cpp @@ -1273,16 +1273,9 @@ void SessionPrivate::handleReceived() { auto msgId = *(uint64*)&decryptedInts[4]; auto seqNo = *(uint32*)&decryptedInts[6]; auto needAck = ((seqNo & 0x01) != 0); - auto messageLength = *(uint32*)&decryptedInts[7]; - if (messageLength > kMaxMessageLength) { - LOG(("TCP Error: bad messageLength %1").arg(messageLength)); - TCP_LOG(("TCP Error: bad message %1").arg(Logs::mb(ints, intsCount * kIntSize).str())); - - return restart(); - - } auto fullDataLength = kEncryptedHeaderIntsCount * kIntSize + messageLength; // Without padding. + auto badMessageLength = (messageLength > kMaxMessageLength); // Can underflow, but it is an unsigned type, so we just check the range later. auto paddingSize = static_cast(encryptedBytesCount) - static_cast(fullDataLength); @@ -1290,7 +1283,7 @@ void SessionPrivate::handleReceived() { #ifdef TDESKTOP_MTPROTO_OLD constexpr auto kMinPaddingSize_oldmtp = 0U; constexpr auto kMaxPaddingSize_oldmtp = 15U; - auto badMessageLength = (/*paddingSize < kMinPaddingSize_oldmtp || */paddingSize > kMaxPaddingSize_oldmtp); + badMessageLength |= (/*paddingSize < kMinPaddingSize_oldmtp || */paddingSize > kMaxPaddingSize_oldmtp); auto hashedDataLength = badMessageLength ? encryptedBytesCount : fullDataLength; auto sha1ForMsgKeyCheck = hashSha1(decryptedInts, hashedDataLength); @@ -1305,7 +1298,7 @@ void SessionPrivate::handleReceived() { #else // TDESKTOP_MTPROTO_OLD constexpr auto kMinPaddingSize = 12U; constexpr auto kMaxPaddingSize = 1024U; - auto badMessageLength = (paddingSize < kMinPaddingSize || paddingSize > kMaxPaddingSize); + badMessageLength |= (paddingSize < kMinPaddingSize || paddingSize > kMaxPaddingSize); std::array sha256Buffer = { { 0 } }; diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 65a001655a..217a930e1f 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -689,6 +689,7 @@ void QueryQuietHours() { bool FocusAssistBlocks = false; +// Thanks https://www.withinrafael.com/2019/09/19/determine-if-your-app-is-in-a-focus-assist-profiles-priority-list/ void QueryFocusAssist() { ComPtr quietHoursSettings; auto hr = CoCreateInstance( @@ -709,18 +710,22 @@ void QueryFocusAssist() { return; } const auto profileName = QString::fromWCharArray(profileId); - if (profileName.endsWith(".unrestricted", Qt::CaseInsensitive)) { - if (FocusAssistBlocks) { - LOG(("Focus Assist: Unrestricted.")); - FocusAssistBlocks = false; - } - return; - } else if (profileName.endsWith(".alarmsonly", Qt::CaseInsensitive)) { + if (profileName.endsWith(".alarmsonly", Qt::CaseInsensitive)) { if (!FocusAssistBlocks) { LOG(("Focus Assist: Alarms Only.")); FocusAssistBlocks = true; } return; + } else if (!profileName.endsWith(".priorityonly", Qt::CaseInsensitive)) { + if (!profileName.endsWith(".unrestricted", Qt::CaseInsensitive)) { + LOG(("Focus Assist Warning: Unknown profile '%1'" + ).arg(profileName)); + } + if (FocusAssistBlocks) { + LOG(("Focus Assist: Unrestricted.")); + FocusAssistBlocks = false; + } + return; } const auto appUserModelId = std::wstring(AppUserModelId::getId()); auto blocked = true;