[OpenSim] Sometimes we are given invalid born strings, don't crash!

This commit is contained in:
Liru Færs
2019-08-26 08:31:32 -04:00
parent a20f4450e9
commit 4b36cd4a58
2 changed files with 13 additions and 7 deletions

View File

@@ -172,7 +172,8 @@ void LLAvatarListEntry::processProperties(void* data, EAvatarProcessorType type)
{
using namespace boost::gregorian;
int year, month, day;
if (sscanf(pAvatarData->born_on.c_str(),"%d/%d/%d",&month,&day,&year) == 3)
const auto born = pAvatarData->born_on;
if (!born.empty() && sscanf(born.c_str(),"%d/%d/%d",&month,&day,&year) == 3)
try
{
mAge = (day_clock::local_day() - date(year, month, day)).days();
@@ -187,7 +188,7 @@ void LLAvatarListEntry::processProperties(void* data, EAvatarProcessorType type)
}
else // Something failed, resend request
{
LL_WARNS() << "Failed to extract age from APT_PROPERTIES for " << mID << ", received \"" << pAvatarData->born_on << "\". Requesting properties again." << LL_ENDL;
LL_WARNS() << "Failed to extract age from APT_PROPERTIES for " << mID << ", received \"" << born << "\". Requesting properties again." << LL_ENDL;
inst.sendAvatarPropertiesRequest(mID);
}
}

View File

@@ -194,11 +194,16 @@ void LLPanelAvatarSecondLife::processProperties(void* data, EAvatarProcessorType
{
using namespace boost::gregorian;
int year, month, day;
sscanf(pAvatarData->born_on.c_str(),"%d/%d/%d", &month, &day, &year);
date birthday(year, month, day), today(day_clock::local_day());
std::ostringstream born_on;
born_on << pAvatarData->born_on << " (" << today - birthday << ')';
childSetValue("born", born_on.str());
const auto& born = pAvatarData->born_on;
if (!born.empty() && sscanf(born.c_str(),"%d/%d/%d", &month, &day, &year) == 3 // Make sure input is valid
&& month > 0 && month <= 12 && day > 0 && day <= 31 && year >= 1400) // Don't use numbers that gregorian will choke on
{
date birthday(year, month, day), today(day_clock::local_day());
std::ostringstream born_on;
born_on << pAvatarData->born_on << " (" << today - birthday << ')';
childSetValue("born", born_on.str());
}
else childSetValue("born", born);
}
bool allow_publish = (pAvatarData->flags & AVATAR_ALLOW_PUBLISH);