aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Grittner <kgrittn@postgresql.org>2013-12-27 15:41:46 -0600
committerKevin Grittner <kgrittn@postgresql.org>2013-12-27 15:41:46 -0600
commitb2d80147d5a3d0a5815c5b8e63a6fd9cef17f4a7 (patch)
tree732420b8a7a9be5feb852e3c7683cc156aa64971
parent69f77d75658821ddd6ecf102a7ab4b27eb316d80 (diff)
downloadpostgresql-b2d80147d5a3d0a5815c5b8e63a6fd9cef17f4a7.tar.gz
postgresql-b2d80147d5a3d0a5815c5b8e63a6fd9cef17f4a7.zip
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.
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 89fb28a402b..5d2e3b33db8 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -482,7 +482,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
bool nulls[10];
HeapTuple tuple;
PgBackendStatus *beentry;
- SockAddr zero_clientaddr;
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));
@@ -515,6 +514,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[3] = CStringGetTextDatum("<command string not enabled>");
@@ -544,7 +545,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[8] = true;
nulls[9] = true;
@@ -797,7 +798,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)
@@ -844,7 +845,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)