1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-10 09:21:54 +03:00

Fix misplaced right paren bugs in pgstatfuncs.c.

The bug would only show up if the C sockaddr structure contained
zero in the first byte for a valid address; otherwise it would
fail to fail, which is probably why it went unnoticed for so long.

Patch submitted by Joel Jacobson after seeing an article by Andrey
Karpov in which he reports finding this through static code
analysis using PVS-Studio.  While I was at it I moved a definition
of a local variable referenced in the buggy code to a more local
context.

Backpatch to all supported branches.
This commit is contained in:
Kevin Grittner 2013-12-27 15:41:18 -06:00
parent 035226c61b
commit 1f069d21d3

View File

@ -587,7 +587,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
bool nulls[12];
HeapTuple tuple;
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));
@ -628,6 +627,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
/* Values only available to same user or superuser */
if (superuser() || beentry->st_userid == GetUserId())
{
SockAddr zero_clientaddr;
if (*(beentry->st_activity) == '\0')
{
values[4] = CStringGetTextDatum("<command string not enabled>");
@ -657,7 +658,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr) == 0))
sizeof(zero_clientaddr)) == 0)
{
nulls[9] = true;
nulls[10] = true;
@ -919,7 +920,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr) == 0))
sizeof(zero_clientaddr)) == 0)
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)
@ -966,7 +967,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr) == 0))
sizeof(zero_clientaddr)) == 0)
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)