From 80edd0b05954a303a965fc0737ceb8294f335a11 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 27 Feb 2019 02:41:16 +0300 Subject: [PATCH] Add UTF-8 checks for user names after they are loaded from database. GitOrigin-RevId: e99c0b2a60791c683ad4c72b224cf6123598f756 --- td/telegram/ContactsManager.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index c2072e3f..ed2b4abd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -48,6 +48,7 @@ #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" +#include "td/utils/utf8.h" #include #include @@ -5359,6 +5360,19 @@ void ContactsManager::on_load_user_from_database(UserId user_id, string value) { log_event_parse(*u, value).ensure(); + if (!check_utf8(u->first_name)) { + LOG(ERROR) << "Have invalid " << user_id << " first name \"" << u->first_name << '"'; + u->first_name.clear(); + } + if (!check_utf8(u->last_name)) { + LOG(ERROR) << "Have invalid " << user_id << " last name \"" << u->last_name << '"'; + u->last_name.clear(); + } + if (!check_utf8(u->username)) { + LOG(ERROR) << "Have invalid " << user_id << " username \"" << u->username << '"'; + u->username.clear(); + } + u->is_saved = true; u->is_status_saved = true; update_user(u, user_id, true, true);