From 9b5cc408ebfe3fa896ce24fe9a93014e99fea974 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Nov 2024 18:31:08 +0100 Subject: [PATCH] GDALVectorTranslate(): fix null-ptr dereference when no source driver --- apps/ogr2ogr_lib.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/ogr2ogr_lib.cpp b/apps/ogr2ogr_lib.cpp index 27969eb6cf07..7dadc2a70847 100644 --- a/apps/ogr2ogr_lib.cpp +++ b/apps/ogr2ogr_lib.cpp @@ -4907,9 +4907,11 @@ SetupTargetLayer::Setup(OGRLayer *poSrcLayer, const char *pszNewLayerName, std::map oMapResolved; /* Determine if NUMERIC field width narrowing is allowed */ + auto poSrcDriver = m_poSrcDS->GetDriver(); const char *pszSrcWidthIncludesDecimalSeparator{ - m_poSrcDS->GetDriver()->GetMetadataItem( - "DMD_NUMERIC_FIELD_WIDTH_INCLUDES_DECIMAL_SEPARATOR")}; + poSrcDriver ? poSrcDriver->GetMetadataItem( + "DMD_NUMERIC_FIELD_WIDTH_INCLUDES_DECIMAL_SEPARATOR") + : nullptr}; const bool bSrcWidthIncludesDecimalSeparator{ pszSrcWidthIncludesDecimalSeparator && EQUAL(pszSrcWidthIncludesDecimalSeparator, "YES")}; @@ -4920,8 +4922,9 @@ SetupTargetLayer::Setup(OGRLayer *poSrcLayer, const char *pszNewLayerName, pszDstWidthIncludesDecimalSeparator && EQUAL(pszDstWidthIncludesDecimalSeparator, "YES")}; const char *pszSrcWidthIncludesMinusSign{ - m_poSrcDS->GetDriver()->GetMetadataItem( - "DMD_NUMERIC_FIELD_WIDTH_INCLUDES_SIGN")}; + poSrcDriver ? poSrcDriver->GetMetadataItem( + "DMD_NUMERIC_FIELD_WIDTH_INCLUDES_SIGN") + : nullptr}; const bool bSrcWidthIncludesMinusSign{ pszSrcWidthIncludesMinusSign && EQUAL(pszSrcWidthIncludesMinusSign, "YES")};