Skip to content

Commit 5e5d471

Browse files
committed
OGRSpatialReference::FindBestMatch(): fix potential nullptr deref introduced by 4ac0e90 (not affecting releases)
1 parent 9583c4d commit 5e5d471

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

ogr/ogrspatialreference.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10350,34 +10350,38 @@ OGRSpatialReference::FindBestMatch(int nMinimumMatchConfidence,
1035010350

1035110351
auto poBaseGeogCRS =
1035210352
std::unique_ptr<OGRSpatialReference>(poSRS->CloneGeogCS());
10353-
10354-
// If the base geographic SRS of the SRS is EPSG:4326
10355-
// with TOWGS84[0,0,0,0,0,0], then just use the official
10356-
// SRS code
10357-
// Same with EPSG:4258 (ETRS89), since it's the only known
10358-
// TOWGS84[] style transformation to WGS 84, and given the
10359-
// "fuzzy" nature of both ETRS89 and WGS 84, there's little
10360-
// chance that a non-NULL TOWGS84[] will emerge.
10361-
const char *pszAuthorityName = nullptr;
10362-
const char *pszAuthorityCode = nullptr;
10363-
const char *pszBaseAuthorityName = nullptr;
10364-
const char *pszBaseAuthorityCode = nullptr;
10365-
const char *pszBaseName = poBaseGeogCRS->GetName();
10366-
if (adfTOWGS84 == std::vector<double>(7) &&
10367-
(pszAuthorityName = poSRS->GetAuthorityName(nullptr)) != nullptr &&
10368-
EQUAL(pszAuthorityName, "EPSG") &&
10369-
(pszAuthorityCode = poSRS->GetAuthorityCode(nullptr)) != nullptr &&
10370-
(pszBaseAuthorityName = poBaseGeogCRS->GetAuthorityName(nullptr)) !=
10371-
nullptr &&
10372-
EQUAL(pszBaseAuthorityName, "EPSG") &&
10373-
(pszBaseAuthorityCode = poBaseGeogCRS->GetAuthorityCode(nullptr)) !=
10374-
nullptr &&
10375-
(EQUAL(pszBaseAuthorityCode, "4326") ||
10376-
EQUAL(pszBaseAuthorityCode, "4258") ||
10377-
// For ETRS89-XXX [...] new CRS added in EPSG 12.033+
10378-
(pszBaseName && STARTS_WITH(pszBaseName, "ETRS89"))))
10379-
{
10380-
poSRS->importFromEPSG(atoi(pszAuthorityCode));
10353+
if (poBaseGeogCRS)
10354+
{
10355+
// If the base geographic SRS of the SRS is EPSG:4326
10356+
// with TOWGS84[0,0,0,0,0,0], then just use the official
10357+
// SRS code
10358+
// Same with EPSG:4258 (ETRS89), since it's the only known
10359+
// TOWGS84[] style transformation to WGS 84, and given the
10360+
// "fuzzy" nature of both ETRS89 and WGS 84, there's little
10361+
// chance that a non-NULL TOWGS84[] will emerge.
10362+
const char *pszAuthorityName = nullptr;
10363+
const char *pszAuthorityCode = nullptr;
10364+
const char *pszBaseAuthorityName = nullptr;
10365+
const char *pszBaseAuthorityCode = nullptr;
10366+
const char *pszBaseName = poBaseGeogCRS->GetName();
10367+
if (adfTOWGS84 == std::vector<double>(7) &&
10368+
(pszAuthorityName = poSRS->GetAuthorityName(nullptr)) !=
10369+
nullptr &&
10370+
EQUAL(pszAuthorityName, "EPSG") &&
10371+
(pszAuthorityCode = poSRS->GetAuthorityCode(nullptr)) !=
10372+
nullptr &&
10373+
(pszBaseAuthorityName =
10374+
poBaseGeogCRS->GetAuthorityName(nullptr)) != nullptr &&
10375+
EQUAL(pszBaseAuthorityName, "EPSG") &&
10376+
(pszBaseAuthorityCode =
10377+
poBaseGeogCRS->GetAuthorityCode(nullptr)) != nullptr &&
10378+
(EQUAL(pszBaseAuthorityCode, "4326") ||
10379+
EQUAL(pszBaseAuthorityCode, "4258") ||
10380+
// For ETRS89-XXX [...] new CRS added in EPSG 12.033+
10381+
(pszBaseName && STARTS_WITH(pszBaseName, "ETRS89"))))
10382+
{
10383+
poSRS->importFromEPSG(atoi(pszAuthorityCode));
10384+
}
1038110385
}
1038210386

1038310387
CPLFree(pahSRS);

0 commit comments

Comments
 (0)