From d26fe37010ec6ed1d83423607bfcae14335d0dbd Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 14 Nov 2021 17:37:19 +0100 Subject: [PATCH] Disallow displaynames with only spaces or control characters --- src/Cache.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 0fdf8dd3..c22cd0d6 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -3828,17 +3828,24 @@ Cache::getMembersWithKeys(const std::string &room_id, bool verified_only) QString Cache::displayName(const QString &room_id, const QString &user_id) { - if (auto info = getMember(room_id.toStdString(), user_id.toStdString()); - info && !info->name.empty()) - return QString::fromStdString(info->name); + return QString::fromStdString(displayName(room_id.toStdString(), user_id.toStdString())); +} - return user_id; +static bool +isDisplaynameSafe(const std::string &s) +{ + for (QChar c : QString::fromStdString(s).toUcs4()) { + if (c.isPrint() && !c.isSpace()) + return false; + } + + return true; } std::string Cache::displayName(const std::string &room_id, const std::string &user_id) { - if (auto info = getMember(room_id, user_id); info && !info->name.empty()) + if (auto info = getMember(room_id, user_id); info && !isDisplaynameSafe(info->name)) return info->name; return user_id;