Skip to content

Commit 1f069d2

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 035226c commit 1f069d2

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
@@ -587,7 +587,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
587587
bool nulls[12];
588588
HeapTuple tuple;
589589
PgBackendStatus *beentry;
590-
SockAddr zero_clientaddr;
591590

592591
MemSet(values, 0, sizeof(values));
593592
MemSet(nulls, 0, sizeof(nulls));
@@ -628,6 +627,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
628627
/* Values only available to same user or superuser */
629628
if (superuser() || beentry->st_userid == GetUserId())
630629
{
630+
SockAddr zero_clientaddr;
631+
631632
if (*(beentry->st_activity) == '\0')
632633
{
633634
values[4] = CStringGetTextDatum("<command string not enabled>");
@@ -657,7 +658,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
657658
/* A zeroed client addr means we don't know */
658659
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
659660
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
660-
sizeof(zero_clientaddr) == 0))
661+
sizeof(zero_clientaddr)) == 0)
661662
{
662663
nulls[9] = true;
663664
nulls[10] = true;
@@ -919,7 +920,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
919920
/* A zeroed client addr means we don't know */
920921
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
921922
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
922-
sizeof(zero_clientaddr) == 0))
923+
sizeof(zero_clientaddr)) == 0)
923924
PG_RETURN_NULL();
924925

925926
switch (beentry->st_clientaddr.addr.ss_family)
@@ -966,7 +967,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
966967
/* A zeroed client addr means we don't know */
967968
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
968969
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
969-
sizeof(zero_clientaddr) == 0))
970+
sizeof(zero_clientaddr)) == 0)
970971
PG_RETURN_NULL();
971972

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy