gdalinfo: fix bound checking for value of -sds argument

This commit is contained in:
Even Rouault 2024-11-21 18:38:07 +01:00
parent 5a7aac3e76
commit b2f16324e8
No known key found for this signature in database
GPG Key ID: 33EBBFC47B3DD87D
2 changed files with 4 additions and 3 deletions

View File

@ -194,6 +194,7 @@ MAIN_START(argc, argv)
else
{
char **papszSubdatasets = GDALGetMetadata(hDataset, "SUBDATASETS");
const int nSubdatasets = CSLCount(papszSubdatasets) / 2;
char *pszSubDest = static_cast<char *>(
CPLMalloc(strlen(sOptionsForBinary.osDest.c_str()) + 32));
@ -205,11 +206,11 @@ MAIN_START(argc, argv)
CPLString osTemp;
const char *pszFormat = nullptr;
if (CSLCount(papszSubdatasets) / 2 < 10)
if (nSubdatasets < 10)
{
pszFormat = "%s_%d";
}
else if (CSLCount(papszSubdatasets) / 2 < 100)
else if (nSubdatasets < 100)
{
pszFormat = "%s_%002d";
}

View File

@ -190,7 +190,7 @@ MAIN_START(argc, argv)
if (sOptionsForBinary.nSubdataset > 0)
{
char **papszSubdatasets = GDALGetMetadata(hDataset, "SUBDATASETS");
int nSubdatasets = CSLCount(papszSubdatasets);
const int nSubdatasets = CSLCount(papszSubdatasets) / 2;
if (nSubdatasets > 0 &&
sOptionsForBinary.nSubdataset <= nSubdatasets)