]> granicus.if.org Git - postgresql/commitdiff
Fix misplaced right paren bugs in pgstatfuncs.c.
authorKevin Grittner <kgrittn@postgresql.org>
Fri, 27 Dec 2013 21:41:02 +0000 (15:41 -0600)
committerKevin Grittner <kgrittn@postgresql.org>
Fri, 27 Dec 2013 21:41:02 +0000 (15:41 -0600)
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.

src/backend/utils/adt/pgstatfuncs.c

index 6f2514748572c8bfd91d56d33964078136a8e8ad..97a4754e924a27820753bf06a1c1da6b670ab36d 100644 (file)
@@ -600,7 +600,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
                bool            nulls[14];
                HeapTuple       tuple;
                PgBackendStatus *beentry;
-               SockAddr        zero_clientaddr;
 
                MemSet(values, 0, sizeof(values));
                MemSet(nulls, 0, sizeof(nulls));
@@ -641,6 +640,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;
+
                        switch (beentry->st_state)
                        {
                                case STATE_IDLE:
@@ -692,7 +693,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[11] = true;
                                nulls[12] = true;
@@ -956,7 +957,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)
@@ -1003,7 +1004,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)