From 2f2d01dc413adacdd6372c3da96a22d95cfbc680 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 9 Apr 2015 19:53:01 +0000 Subject: [PATCH] set max GxsId nickname size to some arbitrary value to avoid crazy long nicknames crafted to break the GUI. This should also be checked when de-serialising groups at a wider scale for group names in general git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8125 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsidentity.h | 3 ++- retroshare-gui/src/gui/Identity/IdDialog.cpp | 2 +- .../src/gui/Identity/IdEditDialog.cpp | 17 ++++++++++++++--- retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 53f66dec8..7726928b5 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -44,7 +44,6 @@ extern RsIdentity *rsIdentity; // GroupFlags: Only one so far: #define RSGXSID_GROUPFLAG_REALID 0x0001 - // THESE ARE FLAGS FOR INTERFACE. #define RSID_TYPE_MASK 0xff00 #define RSID_RELATION_MASK 0x00ff @@ -60,6 +59,8 @@ extern RsIdentity *rsIdentity; #define RSRECOGN_MAX_TAGINFO 5 +#define RSID_MAXIMUM_NICKNAME_SIZE 30 + std::string rsIdTypeToString(uint32_t idtype); class GxsReputation diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 1a06ced7f..4be642b6b 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -390,7 +390,7 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, if (!item) item = new QTreeWidgetItem(); - item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str())); + item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE)); item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId.toStdString())); item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ; diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index 66f65104d..726ef10ca 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -257,7 +257,7 @@ void IdEditDialog::loadExistingId(uint32_t token) // force - incase it wasn't triggered. idTypeToggled(true); - ui->lineEdit_Nickname->setText(QString::fromUtf8(mEditGroup.mMeta.mGroupName.c_str())); + ui->lineEdit_Nickname->setText(QString::fromUtf8(mEditGroup.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE)); ui->lineEdit_KeyId->setText(QString::fromStdString(mEditGroup.mMeta.mGroupId.toStdString())); if (realid) @@ -297,7 +297,7 @@ void IdEditDialog::checkNewTag() { std::string tag = ui->plainTextEdit_Tag->toPlainText().toStdString(); RsGxsId id ( ui->lineEdit_KeyId->text().toStdString()); - std::string name = ui->lineEdit_Nickname->text().toUtf8().data(); + std::string name = ui->lineEdit_Nickname->text().left(RSID_MAXIMUM_NICKNAME_SIZE).toUtf8().data(); QString desc; bool ok = tagDetails(id, name, tag, desc); @@ -488,7 +488,12 @@ void IdEditDialog::createId() std::cerr << std::endl; return; } - + if (groupname.size() > RSID_MAXIMUM_NICKNAME_SIZE) + { + std::cerr << "IdEditDialog::createId() Nickname too long (max " << RSID_MAXIMUM_NICKNAME_SIZE<< " chars)"; + std::cerr << std::endl; + return; + } RsIdentityParameters params; params.nickname = groupname; params.isPgpLinked = (ui->radioButton_GpgId->isChecked()); @@ -538,6 +543,12 @@ void IdEditDialog::updateId() std::cerr << std::endl; return; } + if (groupname.size() > RSID_MAXIMUM_NICKNAME_SIZE) + { + std::cerr << "IdEditDialog::createId() Nickname too long (max " << RSID_MAXIMUM_NICKNAME_SIZE << " chars)"; + std::cerr << std::endl; + return; + } mEditGroup.mMeta.mGroupName = groupname; diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index 0a5f11ac9..2cb4e7faf 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -828,7 +828,7 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi QString GxsIdDetails::getName(const RsIdentityDetails &details) { - QString name = QString::fromUtf8(details.mNickname.c_str()); + QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); std::list::const_iterator it; for (it = details.mRecognTags.begin(); it != details.mRecognTags.end(); ++it) @@ -843,7 +843,7 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details) { QString comment; -QString nickname = details.mNickname.empty()?tr("[Unknown]"):QString::fromUtf8(details.mNickname.c_str()) ; +QString nickname = details.mNickname.empty()?tr("[Unknown]"):QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE) ; comment = QString("%1:%2
%3:%4").arg(QApplication::translate("GxsIdDetails", "Identity name"), nickname,