From e9c0e8c80595315921f2ae715a8ca6eca4a19558 Mon Sep 17 00:00:00 2001 From: drons Date: Sun, 5 Nov 2023 00:58:08 +0300 Subject: [PATCH] createOperations(): Fix possible null dereference on invalid WKT input (#3945) --- src/iso19111/factory.cpp | 7 ++++++- test/unit/test_factory.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 7b2d1634c1..5115030cce 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -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( + auto crs(util::nn_dynamic_pointer_cast( createGeodeticCRS(code, true))); + if (!crs) { + throw NoSuchAuthorityCodeException("geographicCRS not found", + d->authority(), code); + } + return NN_NO_CHECK(crs); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index f2a4d96371..ee575e3aa5 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -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(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"),