[geos-commits] [SCM] GEOS branch main updated. 3c7205e09413f62e1c940052c2cf376bfb36f080

git at osgeo.org git at osgeo.org
Wed Sep 8 14:23:40 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  3c7205e09413f62e1c940052c2cf376bfb36f080 (commit)
      from  6839f11f7cf27ed051a9900224e50a56a7d92f21 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3c7205e09413f62e1c940052c2cf376bfb36f080
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Sep 8 14:23:34 2021 -0700

    Guard against some null inputs, references #1111

diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 350c685..092e0e2 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2622,7 +2622,7 @@ extern "C" {
 
             // Validate input before taking ownership
             for (std::size_t i = 0; i < nholes; i++) {
-                if (!dynamic_cast<LinearRing*>(holes[i])) {
+                if ((!holes) || (!dynamic_cast<LinearRing*>(holes[i]))) {
                     good_holes = false;
                     break;
                 }
@@ -2635,9 +2635,10 @@ extern "C" {
             // which implies freeing them on exception,
             // see https://trac.osgeo.org/geos/ticket/1111
             if (!(good_holes && good_shell)) {
-                delete shell;
+                if (shell) delete shell;
                 for (std::size_t i = 0; i < nholes; i++) {
-                    delete holes[i];
+                    if (holes && holes[i])
+                        delete holes[i];
                 }
                 if (!good_shell)
                     throw IllegalArgumentException("Shell is not a LinearRing");
diff --git a/tests/unit/capi/GEOSGeom_createPolygonTest.cpp b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
index ee73562..79f426d 100644
--- a/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
+++ b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
@@ -75,6 +75,27 @@ void object::test<2>
         GEOSGeom_destroy(polygon);
 }
 
+template<>
+template<>
+void object::test<3>
+()
+{
+    GEOSGeometry* shell = nullptr;
+    GEOSGeometry** holes = nullptr;
+    unsigned int nholes = 0;
+
+    // Returns null on exception, wrong input type for shell
+    GEOSGeometry* polygon = GEOSGeom_createPolygon(shell, holes, 0);
+    ensure(polygon == nullptr);
+
+    // Returns null on exception, wrong input type for shell
+    GEOSGeometry* polygon = GEOSGeom_createPolygon(shell, holes, 1);
+    ensure(polygon == nullptr);
+
+    // Shouldn't need this
+    if (polygon)
+        GEOSGeom_destroy(polygon);
+}
 
 } // namespace tut
 

-----------------------------------------------------------------------

Summary of changes:
 capi/geos_ts_c.cpp                             |  7 ++++---
 tests/unit/capi/GEOSGeom_createPolygonTest.cpp | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list