1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-04 09:43:08 +02:00

Fix segfault on delayed connection errors.

Connection errors could cause a segfault if the error was delayed enough to pass the initial call to sckClientOpenWait() and the error was instead thrown by a subsequent call to sckClientOpenWait(), which was not correctly initializing a variable required for error handling.

While this can be produced fairly easily in a test environment, I was unable to craft a unit test to hit this exact condition, probably due to timing. The new code still has full coverage and I added several comments to help prevent regressions.
This commit is contained in:
David Steele 2024-08-16 10:56:07 +07:00 committed by GitHub
parent 04ef43d9ed
commit 60f96429b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -14,6 +14,19 @@
<p>Fix permissions when <cmd>restore</cmd> run as root user.</p>
</release-item>
<release-item>
<github-issue id="2420"/>
<github-pull-request id="2422"/>
<release-item-contributor-list>
<release-item-ideator id="anton.glushakov"/>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="david.christensen"/>
</release-item-contributor-list>
<p>Fix segfault on delayed connection errors.</p>
</release-item>
<release-item>
<github-issue id="2418"/>
<github-pull-request id="2421"/>

View File

@ -159,10 +159,17 @@ sckClientOpen(THIS_VOID)
{
SckClientOpenData *const openDataWait = lstGet(openDataList, openDataIdx);
if (openDataWait->fd != 0 && sckClientOpenWait(openDataWait, 0))
if (openDataWait->fd != 0)
{
// Set so the connection will be closed on error
openData = openDataWait;
break;
// Check if the connection has completed without waiting
if (sckClientOpenWait(openData, 0))
break;
// Reset to NULL if the connection is still waiting so another connection can be attempted
openData = NULL;
}
}
@ -233,6 +240,8 @@ sckClientOpen(THIS_VOID)
}
CATCH_ANY()
{
ASSERT(openData != NULL);
// Close socket
close(openData->fd);