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

Commit 28b60aa

Browse files
committed
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.
1 parent 663f841 commit 28b60aa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
601601
bool nulls[14];
602602
HeapTuple tuple;
603603
PgBackendStatus *beentry;
604-
SockAddr zero_clientaddr;
605604

606605
MemSet(values, 0, sizeof(values));
607606
MemSet(nulls, 0, sizeof(nulls));
@@ -642,6 +641,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
642641
/* Values only available to same user or superuser */
643642
if (superuser() || beentry->st_userid == GetUserId())
644643
{
644+
SockAddr zero_clientaddr;
645+
645646
switch (beentry->st_state)
646647
{
647648
case STATE_IDLE:
@@ -693,7 +694,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
693694
/* A zeroed client addr means we don't know */
694695
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
695696
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
696-
sizeof(zero_clientaddr) == 0))
697+
sizeof(zero_clientaddr)) == 0)
697698
{
698699
nulls[11] = true;
699700
nulls[12] = true;
@@ -957,7 +958,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
957958
/* A zeroed client addr means we don't know */
958959
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
959960
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
960-
sizeof(zero_clientaddr) == 0))
961+
sizeof(zero_clientaddr)) == 0)
961962
PG_RETURN_NULL();
962963

963964
switch (beentry->st_clientaddr.addr.ss_family)
@@ -1004,7 +1005,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
10041005
/* A zeroed client addr means we don't know */
10051006
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
10061007
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1007-
sizeof(zero_clientaddr) == 0))
1008+
sizeof(zero_clientaddr)) == 0)
10081009
PG_RETURN_NULL();
10091010

10101011
switch (beentry->st_clientaddr.addr.ss_family)

0 commit comments

Comments
 (0)