[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

@@ -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);