1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-02-03 13:21:32 +02:00

Refactor backupBlockIncrMapSize() range handling to satisfy Coverity.

Coverity complained about a possible overflow of result in the prior implementation.

It appears that Coverity was not able to follow the logic through the try block, but refactor and add an assertion to silence the complaint.
This commit is contained in:
David Steele 2025-01-30 14:28:28 -05:00
parent 89615eee65
commit 6e437defa9
2 changed files with 12 additions and 10 deletions

View File

@ -341,28 +341,27 @@ backupBlockIncrMapSize(const ConfigOption optionId, const unsigned int optionKey
FUNCTION_TEST_PARAM(STRING, value);
FUNCTION_TEST_END();
unsigned int result = 0;
int64_t result;
TRY_BEGIN()
{
const int64_t valueI64 = cfgParseSize(value);
result = cfgParseSize(value);
if (valueI64 <= UINT_MAX)
result = (unsigned int)valueI64;
// Error if value is out of range (no need for an error message since that will be generated in the catch block)
if (result <= 0 || result > UINT_MAX)
THROW(OptionInvalidValueError, "");
}
CATCH_ANY()
{
}
TRY_END();
if (result == 0)
{
THROW_FMT(
OptionInvalidValueError, "'%s' is not valid for '%s' option", strZ(value),
cfgParseOptionKeyIdxName(optionId, optionKeyIdx));
}
TRY_END();
FUNCTION_TEST_RETURN(UINT, result);
ASSERT(result > 0 && result < UINT_MAX);
FUNCTION_TEST_RETURN(UINT, (unsigned int)result);
}
// Convert map checksum size

View File

@ -1094,6 +1094,9 @@ testRun(void)
{
TEST_TITLE("block incremental config map");
TEST_ERROR(
backupBlockIncrMapSize(cfgOptRepoBlockSizeMap, 0, STRDEF("0")), OptionInvalidValueError,
"'0' is not valid for 'repo1-block-size-map' option");
TEST_ERROR(
backupBlockIncrMapSize(cfgOptRepoBlockSizeMap, 0, STRDEF("Z")), OptionInvalidValueError,
"'Z' is not valid for 'repo1-block-size-map' option");