Skip to content

Commit

Permalink
createOperations(): Fix possible null dereference on invalid WKT input (
Browse files Browse the repository at this point in the history
  • Loading branch information
drons authored Nov 4, 2023
1 parent 93fdba6 commit e9c0e8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5045,8 +5045,13 @@ AuthorityFactory::createGeodeticCRS(const std::string &code) const {

crs::GeographicCRSNNPtr
AuthorityFactory::createGeographicCRS(const std::string &code) const {
return NN_NO_CHECK(util::nn_dynamic_pointer_cast<crs::GeographicCRS>(
auto crs(util::nn_dynamic_pointer_cast<crs::GeographicCRS>(
createGeodeticCRS(code, true)));
if (!crs) {
throw NoSuchAuthorityCodeException("geographicCRS not found",
d->authority(), code);
}
return NN_NO_CHECK(crs);
}

// ---------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions test/unit/test_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,18 @@ TEST(factory, AuthorityFactory_createGeodeticCRS_geocentric) {

// ---------------------------------------------------------------------------

TEST(factory, AuthorityFactory_createGeographicCRS) {
auto factory = AuthorityFactory::create(DatabaseContext::create(), "EPSG");
auto crs = factory->createGeographicCRS("4979");
ASSERT_TRUE(nn_dynamic_pointer_cast<GeographicCRS>(crs) != nullptr);
ASSERT_EQ(crs->identifiers().size(), 1U);
EXPECT_EQ(crs->identifiers()[0]->code(), "4979");

EXPECT_THROW(factory->createGeographicCRS("4978"), FactoryException);
}

// ---------------------------------------------------------------------------

TEST(factory, AuthorityFactory_createVerticalCRS) {
auto factory = AuthorityFactory::create(DatabaseContext::create(), "EPSG");
EXPECT_THROW(factory->createVerticalCRS("-1"),
Expand Down

0 comments on commit e9c0e8c

Please sign in to comment.