Skip to content

Commit 51e1751

Browse files
committed
Fix overflows inserting invalid values into stats map
Signed-off-by: Rye <[email protected]>
1 parent abc3d7e commit 51e1751

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

indra/llcommon/llsys.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ class Stats
713713
void add(const LLSD::String& name, const T& value,
714714
typename boost::enable_if<boost::is_integral<T> >::type* = 0)
715715
{
716-
mStats[name] = LLSD::Integer(value);
716+
mStats[name] = LLSD::Integer(llmin<T>(value, S32_MAX));
717717
}
718718

719719
// Store every floating-point type as LLSD::Real.
@@ -1112,9 +1112,10 @@ LLSD LLMemoryInfo::loadStatsMap()
11121112
LLSD::String key(matched[1].first, matched[1].second);
11131113
LLSD::String value_str(matched[2].first, matched[2].second);
11141114
LLSD::Integer value(0);
1115+
S64 intval = 0;
11151116
try
11161117
{
1117-
value = boost::lexical_cast<LLSD::Integer>(value_str);
1118+
intval = llclamp(boost::lexical_cast<S64>(value_str), S32_MIN, S32_MAX);
11181119
}
11191120
catch (const boost::bad_lexical_cast&)
11201121
{
@@ -1123,6 +1124,7 @@ LLSD LLMemoryInfo::loadStatsMap()
11231124
<< line << LL_ENDL;
11241125
continue;
11251126
}
1127+
value = LLSD::Integer(intval);
11261128
// Store this statistic.
11271129
stats.add(key, value);
11281130
}

0 commit comments

Comments
 (0)