提交 280416b7 编写于 作者: D Daniel Gustafsson

Guard against possible NULL pointer dereferencing

Improves defensiveness of programming around pointer derefencing to
ensure that we don't risk a NULL pointer. Most of these are quite
straight-forward, those of note are discussed below.

In doDispatchDtxProtocolCommand() we relied on the result data being
created in zeroed out memory on CdbDispatchDtxProtocolCommand() which
isn't guaranteed for every compiler. Explcitly set numResults to zero
and also check the results for NULL.

Per multiple reports by Coverity
上级 8793c3bd
......@@ -744,8 +744,9 @@ static void indexParts(PartitionIndexNode **np, bool isDefault)
PartitionIndexNode *n = *np;
bool found;
if (n)
{
if (!n)
return;
int x;
x = bms_first_from(n->index, 0);
while (x >= 0)
......@@ -780,7 +781,6 @@ static void indexParts(PartitionIndexNode **np, bool isDefault)
entry->partList = lappend_oid(entry->partList, n->parchildrelid);
x = bms_first_from(n->index, x + 1);
}
}
if (n->children)
{
......@@ -1229,8 +1229,9 @@ dumpPartsIndexInfo(PartitionIndexNode *n, int level)
StringInfoData logicalIndexes;
initStringInfo(&logicalIndexes);
if (n)
{
if (!n)
return;
for (int i = 0; i <= level; i++)
appendStringInfo(&logicalIndexes, "%s", " ");
......@@ -1249,8 +1250,6 @@ dumpPartsIndexInfo(PartitionIndexNode *n, int level)
appendStringInfo(&logicalIndexes, "%s ", " )");
elog(DEBUG5, "%s", logicalIndexes.data);
}
if (n->children)
{
......
......@@ -2268,6 +2268,8 @@ doDispatchDtxProtocolCommand(DtxProtocolCommand dtxProtocolCommand, int flags,
for (i = 0; i < resultCount; i++)
PQclear(results[i]);
if (results)
free(results);
return (numOfFailed == 0);
......
......@@ -82,7 +82,7 @@ CdbDispatchDtxProtocolCommand(DtxProtocolCommand dtxProtocolCommand,
CdbDispatcherState ds = {NULL, NULL, NULL};
CdbDispatchResults* pr = NULL;
CdbPgResults cdb_pgresults;
CdbPgResults cdb_pgresults = {NULL, 0};
DispatchCommandDtxProtocolParms dtxProtocolParms;
Gang *primaryGang;
......
......@@ -1641,7 +1641,13 @@ reportBackupResults(InputOptions inputopts, ThreadParmArray *pParmAr)
SegmentDatabase *pSegDB;
ThreadParm *p;
if (pParmAr == NULL || pParmAr->count == 0)
if (pParmAr == NULL)
{
mpp_err_msg(logError, progname, "Report data missing\n");
return 2;
}
if (pParmAr->count == 0)
{
pParmAr->count = 1; /* just use master in this case (early error) */
pParmAr->pData = (ThreadParm *) calloc(1, sizeof(ThreadParm));
......
......@@ -8232,12 +8232,14 @@ formGenericFilePathName(char *keyword, char *pszBackupDirectory, char *pszBackup
{
mpp_err_msg(logWarn, progname, "Backup catalog FileName based on path %s and key %s too long",
pszBackupDirectory, pszBackupKey);
exit_nicely();
}
pszBackupFileName = (char *) malloc(sizeof(char) * (1 + len));
if (pszBackupFileName == NULL)
{
mpp_err_msg(logError, progname, "out of memory");
exit_nicely();
}
strcpy(pszBackupFileName, pszBackupDirectory);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册