提交 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,42 +744,42 @@ 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)
{
int x;
x = bms_first_from(n->index, 0);
while (x >= 0)
entry = (LogicalIndexInfoHashEntry *)hash_search(LogicalIndexInfoHash,
(void *)&x,
HASH_FIND,
&found);
if (!found)
{
entry = (LogicalIndexInfoHashEntry *)hash_search(LogicalIndexInfoHash,
(void *)&x,
HASH_FIND,
&found);
if (!found)
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("error during BuildLogicalIndexInfo. Indexr not found \"%d\" in hash",
x)));
}
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("error during BuildLogicalIndexInfo. Indexr not found \"%d\" in hash",
x)));
}
if (n->isDefault || isDefault)
{
/*
* We keep track of the default node in the PartitionIndexNode
* tree, since we need to output the defaultLevels information
* to the caller.
*/
entry->defaultPartList = lappend(entry->defaultPartList, n);
numIndexesOnDefaultParts++;
}
else
/*
* For regular non-default parts we just track the part oid
* which will be used to get the part constraint.
*/
entry->partList = lappend_oid(entry->partList, n->parchildrelid);
x = bms_first_from(n->index, x + 1);
if (n->isDefault || isDefault)
{
/*
* We keep track of the default node in the PartitionIndexNode
* tree, since we need to output the defaultLevels information
* to the caller.
*/
entry->defaultPartList = lappend(entry->defaultPartList, n);
numIndexesOnDefaultParts++;
}
else
/*
* For regular non-default parts we just track the part oid
* which will be used to get the part constraint.
*/
entry->partList = lappend_oid(entry->partList, n->parchildrelid);
x = bms_first_from(n->index, x + 1);
}
if (n->children)
......@@ -1229,28 +1229,27 @@ dumpPartsIndexInfo(PartitionIndexNode *n, int level)
StringInfoData logicalIndexes;
initStringInfo(&logicalIndexes);
if (n)
{
for (int i = 0; i <= level; i++)
appendStringInfo(&logicalIndexes, "%s", " ");
appendStringInfo(&logicalIndexes, "%d ", n->parchildrelid);
if (!n)
return;
int x;
x = bms_first_from(n->index, 0);
appendStringInfo(&logicalIndexes, "%s ", " (");
for (int i = 0; i <= level; i++)
appendStringInfo(&logicalIndexes, "%s", " ");
while (x >= 0)
{
appendStringInfo(&logicalIndexes, "%d ", x);
x = bms_first_from(n->index, x + 1);
}
appendStringInfo(&logicalIndexes, "%d ", n->parchildrelid);
appendStringInfo(&logicalIndexes, "%s ", " )");
int x;
x = bms_first_from(n->index, 0);
appendStringInfo(&logicalIndexes, "%s ", " (");
elog(DEBUG5, "%s", logicalIndexes.data);
while (x >= 0)
{
appendStringInfo(&logicalIndexes, "%d ", x);
x = bms_first_from(n->index, x + 1);
}
appendStringInfo(&logicalIndexes, "%s ", " )");
elog(DEBUG5, "%s", logicalIndexes.data);
if (n->children)
{
......
......@@ -2268,7 +2268,9 @@ doDispatchDtxProtocolCommand(DtxProtocolCommand dtxProtocolCommand, int flags,
for (i = 0; i < resultCount; i++)
PQclear(results[i]);
free(results);
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.
先完成此消息的编辑!
想要评论请 注册