Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5592eba

Browse files
committed
Another round of Coverity fixes
Additional non-security issues/improvements spotted by Coverity. In backend/libpq, no sense trying to protect against port->hba being NULL after we've already dereferenced it in the switch() statement. Prevent against possible overflow due to 32bit arithmitic in basebackup throttling (not yet released, so no security concern). Remove nonsensical check of array pointer against NULL in procarray.c, looks to be a holdover from 9.1 and earlier when there were pointers being used but now it's just an array. Remove pointer check-against-NULL in tsearch/spell.c as we had already dereferenced it above (in the strcmp()). Remove dead code from adt/orderedsetaggs.c, isnull is checked immediately after each tuplesort_getdatum() call and if true we return, so no point checking it again down at the bottom. Remove recently added minor error-condition memory leak in pg_regress.
1 parent b1aebbb commit 5592eba

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

src/backend/libpq/auth.c

+7-11
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ static void
214214
auth_failed(Port *port, int status, char *logdetail)
215215
{
216216
const char *errstr;
217+
char *cdetail;
217218
int errcode_return = ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION;
218219

219220
/*
@@ -273,17 +274,12 @@ auth_failed(Port *port, int status, char *logdetail)
273274
break;
274275
}
275276

276-
if (port->hba)
277-
{
278-
char *cdetail;
279-
280-
cdetail = psprintf(_("Connection matched pg_hba.conf line %d: \"%s\""),
281-
port->hba->linenumber, port->hba->rawline);
282-
if (logdetail)
283-
logdetail = psprintf("%s\n%s", logdetail, cdetail);
284-
else
285-
logdetail = cdetail;
286-
}
277+
cdetail = psprintf(_("Connection matched pg_hba.conf line %d: \"%s\""),
278+
port->hba->linenumber, port->hba->rawline);
279+
if (logdetail)
280+
logdetail = psprintf("%s\n%s", logdetail, cdetail);
281+
else
282+
logdetail = cdetail;
287283

288284
ereport(FATAL,
289285
(errcode(errcode_return),

src/backend/replication/basebackup.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
227227
/* Setup and activate network throttling, if client requested it */
228228
if (opt->maxrate > 0)
229229
{
230-
throttling_sample = opt->maxrate * 1024 / THROTTLING_FREQUENCY;
230+
throttling_sample =
231+
(int64) opt->maxrate * (int64) 1024 / THROTTLING_FREQUENCY;
231232

232233
/*
233234
* The minimum amount of time for throttling_sample

src/backend/storage/ipc/procarray.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -2302,19 +2302,16 @@ MinimumActiveBackends(int min)
23022302
volatile PGXACT *pgxact = &allPgXact[pgprocno];
23032303

23042304
/*
2305-
* Since we're not holding a lock, need to check that the pointer is
2306-
* valid. Someone holding the lock could have incremented numProcs
2307-
* already, but not yet inserted a valid pointer to the array.
2305+
* Since we're not holding a lock, need to be prepared to deal with
2306+
* garbage, as someone could have incremented numPucs but not yet
2307+
* filled the structure.
23082308
*
23092309
* If someone just decremented numProcs, 'proc' could also point to a
23102310
* PGPROC entry that's no longer in the array. It still points to a
23112311
* PGPROC struct, though, because freed PGPROC entries just go to the
23122312
* free list and are recycled. Its contents are nonsense in that case,
23132313
* but that's acceptable for this function.
23142314
*/
2315-
if (proc == NULL)
2316-
continue;
2317-
23182315
if (proc == MyProc)
23192316
continue; /* do not count myself */
23202317
if (pgxact->xid == InvalidTransactionId)

src/backend/tsearch/spell.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ NIAddAffix(IspellDict *Conf, int flag, char flagflags, const char *mask, const c
404404
Affix->issimple = 0;
405405
Affix->isregis = 1;
406406
RS_compile(&(Affix->reg.regis), (type == FF_SUFFIX) ? true : false,
407-
(mask && *mask) ? mask : VoidString);
407+
*mask ? mask : VoidString);
408408
}
409409
else
410410
{

src/backend/utils/adt/orderedsetaggs.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo,
585585
* trouble, since the cleanup callback will clear the tuplesort later.
586586
*/
587587

588-
if (isnull)
589-
PG_RETURN_NULL();
590-
else
591-
PG_RETURN_DATUM(val);
588+
PG_RETURN_DATUM(val);
592589
}
593590

594591
/*

src/test/regress/pg_regress.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,17 @@ get_alternative_expectfile(const char *expectfile, int i)
11541154
{
11551155
char *last_dot;
11561156
int ssize = strlen(expectfile) + 2 + 1;
1157-
char *tmp = (char *) malloc(ssize);
1158-
char *s = (char *) malloc(ssize);
1157+
char *tmp;
1158+
char *s;
11591159

1160-
if (!tmp || !s)
1160+
if (!(tmp = (char*) malloc(ssize)))
11611161
return NULL;
1162+
1163+
if (!(s = (char*) malloc(ssize)))
1164+
{
1165+
free(tmp);
1166+
return NULL;
1167+
}
11621168

11631169
strcpy(tmp, expectfile);
11641170
last_dot = strrchr(tmp, '.');

0 commit comments

Comments
 (0)