From aadbb3d912af1184fd9c5210e5066d9d92e0dacd Mon Sep 17 00:00:00 2001
From: andreykproductengine <andreykproductengine@lindenlab.com>
Date: Thu, 31 Oct 2019 23:17:10 +0200
Subject: [PATCH] SL-11732 Validation for stored favorites

---
 indra/newview/llfavoritesbar.cpp | 29 +++++++++++++++++++++++------
 indra/newview/llfavoritesbar.h   |  5 ++++-
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index 17952349dc2..347997a69a6 100644
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -1590,14 +1590,29 @@ void LLFavoritesOrderStorage::load()
 												<< (fav_llsd.isMap() ? "" : "un") << "successfully"
 												<< LL_ENDL;
 				in_file.close();
-				user_llsd = fav_llsd[gAgentUsername];
+				if (fav_llsd.isMap() && fav_llsd.has(gAgentUsername))
+				{
+					user_llsd = fav_llsd[gAgentUsername];
 
-				S32 index = 0;
-				for (LLSD::array_iterator iter = user_llsd.beginArray();
+					S32 index = 0;
+					bool needs_validation = gSavedPerAccountSettings.getBOOL("ShowFavoritesOnLogin");
+					for (LLSD::array_iterator iter = user_llsd.beginArray();
 						iter != user_llsd.endArray(); ++iter)
-				{
-					mSortIndexes.insert(std::make_pair(iter->get("id").asUUID(), index));
-					index++;
+					{
+						// Validation
+						LLUUID fv_id = iter->get("id").asUUID();
+						if (needs_validation
+							&& (fv_id.isNull()
+								|| iter->get("asset_id").asUUID().isNull()
+								|| iter->get("name").asString().empty()
+								|| iter->get("slurl").asString().empty()))
+						{
+							mRecreateFavoriteStorage = true;
+						}
+
+						mSortIndexes.insert(std::make_pair(fv_id, index));
+						index++;
+					}
 				}
 			}
 			else
@@ -1841,6 +1856,8 @@ void LLFavoritesOrderStorage::rearrangeFavoriteLandmarks(const LLUUID& source_it
 
 BOOL LLFavoritesOrderStorage::saveFavoritesRecord(bool pref_changed)
 {
+	pref_changed |= mRecreateFavoriteStorage;
+	mRecreateFavoriteStorage = false;
 
 	LLUUID favorite_folder= gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
 	if (favorite_folder.isNull())
diff --git a/indra/newview/llfavoritesbar.h b/indra/newview/llfavoritesbar.h
index d93161fd7ac..571208aa31b 100644
--- a/indra/newview/llfavoritesbar.h
+++ b/indra/newview/llfavoritesbar.h
@@ -248,6 +248,7 @@ class LLFavoritesOrderStorage : public LLSingleton<LLFavoritesOrderStorage>
 	slurls_map_t mSLURLs;
 	std::set<LLUUID> mMissingSLURLs;
 	bool mIsDirty;
+	bool mRecreateFavoriteStorage;
 
 	struct IsNotInFavorites
 	{
@@ -278,7 +279,9 @@ class LLFavoritesOrderStorage : public LLSingleton<LLFavoritesOrderStorage>
 
 inline
 LLFavoritesOrderStorage::LLFavoritesOrderStorage() :
-	mIsDirty(false), mUpdateRequired(false)
+	mIsDirty(false),
+	mUpdateRequired(false),
+	mRecreateFavoriteStorage(false)
 { load(); }
 
 #endif // LL_LLFAVORITESBARCTRL_H
-- 
GitLab