1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +02:00

Use strNewZ() in cases where STRDEF() assignment goes out of scope.

If a variable assigned with STRDEF() is referenced out of scope of the STRDEF() assignment then the value is undefined.

Luckily most of the instances are in tests but there is one in the core code. It is not clear if this is a live bug or not but it certainly needs to be fixed.

Found with -fsanitize=address.
This commit is contained in:
David Steele
2022-03-24 12:26:09 -06:00
parent edf6c70baa
commit 75b26319ae
5 changed files with 7 additions and 7 deletions

View File

@ -675,7 +675,7 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
// Resumable backups must have backup.manifest.copy
if (storageExistsP(storageRepo(), strNewFmt("%s" INFO_COPY_EXT, strZ(manifestFile))))
{
reason = STRDEF("resume is disabled");
reason = strNewZ("resume is disabled");
// Attempt to read the manifest file in the resumable backup to see if it can be used. If any error at all
// occurs then the backup will be considered unusable and a resume will not be attempted.

View File

@ -1748,7 +1748,7 @@ testRun(void)
manifestResume = manifestNewInternal();
manifestResume->pub.info = infoNew(NULL);
manifestResume->pub.data.backupType = backupTypeFull;
manifestResume->pub.data.backupLabel = STRDEF("20191003-105320F");
manifestResume->pub.data.backupLabel = strNewZ("20191003-105320F");
manifestResume->pub.data.pgVersion = PG_VERSION_12;
}
OBJ_NEW_END();

View File

@ -1900,7 +1900,7 @@ testRun(void)
{
manifest = manifestNewInternal();
manifest->pub.info = infoNew(NULL);
manifest->pub.data.backupLabel = STRDEF(TEST_LABEL);
manifest->pub.data.backupLabel = strNewZ(TEST_LABEL);
manifest->pub.data.pgVersion = PG_VERSION_90;
manifest->pub.data.pgCatalogVersion = hrnPgCatalogVersion(PG_VERSION_90);
manifest->pub.data.backupType = backupTypeFull;
@ -2306,7 +2306,7 @@ testRun(void)
{
manifest = manifestNewInternal();
manifest->pub.info = infoNew(NULL);
manifest->pub.data.backupLabel = STRDEF(TEST_LABEL);
manifest->pub.data.backupLabel = strNewZ(TEST_LABEL);
manifest->pub.data.pgVersion = PG_VERSION_10;
manifest->pub.data.pgCatalogVersion = hrnPgCatalogVersion(PG_VERSION_10);
manifest->pub.data.backupType = backupTypeIncr;

View File

@ -1062,7 +1062,7 @@ testRun(void)
OBJ_NEW_BEGIN(Manifest)
{
manifestPrior = manifestNewInternal();
manifestPrior->pub.data.backupLabel = STRDEF("20190101-010101F");
manifestPrior->pub.data.backupLabel = strNewZ("20190101-010101F");
manifestFileAdd(
manifestPrior,

View File

@ -285,7 +285,7 @@ testRun(void)
{
protocolHelperClient.client = OBJ_NEW_ALLOC();
*protocolHelperClient.client = (ProtocolClient){
.name = STRDEF("test"), .state = protocolClientStateIdle, .write = write};
.name = strNewZ("test"), .state = protocolClientStateIdle, .write = write};
memContextCallbackSet(memContextCurrent(), protocolClientFreeResource, protocolHelperClient.client);
}
OBJ_NEW_END();
@ -293,7 +293,7 @@ testRun(void)
OBJ_NEW_BEGIN(Exec)
{
protocolHelperClient.exec = OBJ_NEW_ALLOC();
*protocolHelperClient.exec = (Exec){.name = STRDEF("test"), .command = strNewZ("test"), .processId = INT_MAX};
*protocolHelperClient.exec = (Exec){.name = strNewZ("test"), .command = strNewZ("test"), .processId = INT_MAX};
memContextCallbackSet(memContextCurrent(), execFreeResource, protocolHelperClient.exec);
}
OBJ_NEW_END();