Make positioned queries more defensive.
Validate the filter type range, to avoid crashing on bad ranges. Accept arbitrary type lists in the Nasal API for searching by distance
This commit is contained in:
parent
b2759d018b
commit
761b4835f9
2 changed files with 33 additions and 6 deletions
|
@ -54,6 +54,16 @@ static void validateSGGeod(const SGGeod& geod)
|
|||
}
|
||||
}
|
||||
|
||||
static bool validateFilter(FGPositioned::Filter* filter)
|
||||
{
|
||||
if (filter->maxType() < filter->minType()) {
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "invalid positioned filter specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -231,6 +241,10 @@ FGPositioned::findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilt
|
|||
{
|
||||
validateSGGeod(aPos);
|
||||
|
||||
if (!validateFilter(aFilter)) {
|
||||
return FGPositionedList();
|
||||
}
|
||||
|
||||
FGPositionedList result;
|
||||
Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
|
||||
aRangeNm * SG_NM_TO_METER, aFilter, result, 0xffffff);
|
||||
|
@ -242,6 +256,10 @@ FGPositioned::findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter
|
|||
{
|
||||
validateSGGeod(aPos);
|
||||
|
||||
if (!validateFilter(aFilter)) {
|
||||
return FGPositionedList();
|
||||
}
|
||||
|
||||
int limitMsec = 32;
|
||||
FGPositionedList result;
|
||||
aPartial = Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
|
||||
|
@ -253,12 +271,20 @@ FGPositioned::findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter
|
|||
FGPositionedList
|
||||
FGPositioned::findAllWithIdent(const std::string& aIdent, Filter* aFilter, bool aExact)
|
||||
{
|
||||
if (!validateFilter(aFilter)) {
|
||||
return FGPositionedList();
|
||||
}
|
||||
|
||||
return NavDataCache::instance()->findAllWithIdent(aIdent, aFilter, aExact);
|
||||
}
|
||||
|
||||
FGPositionedList
|
||||
FGPositioned::findAllWithName(const std::string& aName, Filter* aFilter, bool aExact)
|
||||
{
|
||||
if (!validateFilter(aFilter)) {
|
||||
return FGPositionedList();
|
||||
}
|
||||
|
||||
return NavDataCache::instance()->findAllWithName(aName, aFilter, aExact);
|
||||
}
|
||||
|
||||
|
@ -267,6 +293,10 @@ FGPositioned::findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter)
|
|||
{
|
||||
validateSGGeod(aPos);
|
||||
|
||||
if (!validateFilter(aFilter)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FGPositionedList l(findClosestN(aPos, 1, aCutoffNm, aFilter));
|
||||
if (l.empty()) {
|
||||
return NULL;
|
||||
|
|
|
@ -395,13 +395,10 @@ static naRef f_findWithinRange(nasal::CallContext ctx)
|
|||
{
|
||||
SGGeod pos = getPosition(ctx);
|
||||
double range_nm = ctx.requireArg<double>(0);
|
||||
|
||||
FGPositioned::Type ty = FGPositioned::typeFromName(ctx.getArg<std::string>(1));
|
||||
if (ty == FGPositioned::INVALID)
|
||||
naRuntimeError(ctx.c, "invalid filter type specification");
|
||||
|
||||
std::string typeSpec = ctx.getArg<std::string>(1);
|
||||
FGPositioned::TypeFilter filter(FGPositioned::TypeFilter::fromString(typeSpec));
|
||||
|
||||
FGPositioned::TypeFilter filter(ty);
|
||||
|
||||
FGPositionedList items = FGPositioned::findWithinRange(pos, range_nm, &filter);
|
||||
FGPositioned::sortByRange(items, pos);
|
||||
return ctx.to_nasal(items);
|
||||
|
|
Loading…
Reference in a new issue