Skip to content
Permalink
Browse files

VRT: fix use after free added three commits ago in 4470ea8

  • Loading branch information...
rouault committed Mar 15, 2019
1 parent 1af1452 commit de89d5b30008f190bbda54493696da158fb78d41
Showing with 14 additions and 19 deletions.
  1. +14 −19 gdal/frmts/vrt/vrtsources.cpp
@@ -522,7 +522,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
bShared = true;
}

char *pszSrcDSName = nullptr;
CPLString osSrcDSName;
if( pszVRTPath != nullptr && m_bRelativeToVRTOri )
{
bool bDone = false;
@@ -550,8 +550,8 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
}
CPLString osPrefixFilename = pszFilename;
osPrefixFilename.resize(pszLastPart - pszFilename);
pszSrcDSName = CPLStrdup( (osPrefixFilename +
CPLProjectRelativeFilename( pszVRTPath, pszLastPart )).c_str() );
osSrcDSName = osPrefixFilename +
CPLProjectRelativeFilename( pszVRTPath, pszLastPart );
bDone = true;
}
else if( STARTS_WITH_CI(pszSyntax + osPrefix.size(), "{FILENAME}") )
@@ -568,9 +568,9 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
{
const CPLString osSuffix = osFilename.substr(nPos);
osFilename.resize(nPos);
pszSrcDSName = CPLStrdup(
(osPrefix + CPLProjectRelativeFilename(
pszVRTPath, osFilename ) + osSuffix).c_str() );
osSrcDSName =
osPrefix + CPLProjectRelativeFilename(
pszVRTPath, osFilename ) + osSuffix;
bDone = true;
}
}
@@ -579,13 +579,12 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
}
if( !bDone )
{
pszSrcDSName = CPLStrdup(
CPLProjectRelativeFilename( pszVRTPath, pszFilename ) );
osSrcDSName = CPLProjectRelativeFilename( pszVRTPath, pszFilename );
}
}
else
{
pszSrcDSName = CPLStrdup( pszFilename );
osSrcDSName = pszFilename;
}

const char* pszSourceBand = CPLGetXMLValue(psSrc,"SourceBand","1");
@@ -607,7 +606,6 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
{
CPLError( CE_Warning, CPLE_AppDefined,
"Invalid <SourceBand> element in VRTRasterBand." );
CPLFree( pszSrcDSName );
return CE_Failure;
}

@@ -653,13 +651,12 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
{
CPLError( CE_Warning, CPLE_AppDefined,
"Invalid <SourceProperties> element in VRTRasterBand." );
CPLFree( pszSrcDSName );
return CE_Failure;
}
}

char** papszOpenOptions = GDALDeserializeOpenOptionsFromXML(psSrc);
if( strstr(pszSrcDSName,"<VRTDataset") != nullptr )
if( strstr(osSrcDSName.c_str(),"<VRTDataset") != nullptr )
papszOpenOptions =
CSLSetNameValue(papszOpenOptions, "ROOT_PATH", pszVRTPath);

@@ -679,7 +676,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
// annoying reference cycles in situations like you have
// foo.tif and foo.tif.ovr, the later being actually a VRT file
// that points to foo.tif
auto oIter = oMapSharedSources.find(pszSrcDSName);
auto oIter = oMapSharedSources.find(osSrcDSName);
if( oIter != oMapSharedSources.end() )
{
poSrcDS = oIter->second;
@@ -688,7 +685,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
else
{
poSrcDS = static_cast<GDALDataset *>( GDALOpenEx(
pszSrcDSName, nOpenFlags, nullptr,
osSrcDSName, nOpenFlags, nullptr,
(const char* const* )papszOpenOptions, nullptr ) );
if( poSrcDS )
{
@@ -699,7 +696,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
else
{
poSrcDS = static_cast<GDALDataset *>( GDALOpenEx(
pszSrcDSName, nOpenFlags, nullptr,
osSrcDSName, nOpenFlags, nullptr,
(const char* const* )papszOpenOptions, nullptr ) );
}
}
@@ -710,7 +707,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
/* ----------------------------------------------------------------- */
CPLString osUniqueHandle( CPLSPrintf("%p", pUniqueHandle) );
GDALProxyPoolDataset * const proxyDS =
new GDALProxyPoolDataset( pszSrcDSName, nRasterXSize, nRasterYSize,
new GDALProxyPoolDataset( osSrcDSName, nRasterXSize, nRasterYSize,
GA_ReadOnly, bShared, nullptr, nullptr,
osUniqueHandle.c_str() );
proxyDS->SetOpenOptions(papszOpenOptions);
@@ -747,8 +744,6 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,

CSLDestroy(papszOpenOptions);

CPLFree( pszSrcDSName );

if( poSrcDS == nullptr )
return CE_Failure;

@@ -764,7 +759,7 @@ CPLErr VRTSimpleSource::XMLInit( CPLXMLNode *psSrc, const char *pszVRTPath,
}
else if( bAddToMapIfOk )
{
oMapSharedSources[pszSrcDSName] = poSrcDS;
oMapSharedSources[osSrcDSName] = poSrcDS;
}

if( bGetMaskBand )

0 comments on commit de89d5b

Please sign in to comment.
You can’t perform that action at this time.