]> granicus.if.org Git - postgresql/commitdiff
Prevent show_session_authorization from crashing when session_authorization
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Sep 2010 20:53:33 +0000 (16:53 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Sep 2010 20:53:33 +0000 (16:53 -0400)
hasn't been set.

The only known case where this can happen is when show_session_authorization
is invoked in an autovacuum process, which is possible if an index function
calls it, as for example in bug #5669 from Andrew Geery.  We could perhaps
try to return a sensible value, such as the name of the cluster-owning
superuser; but that seems like much more trouble than the case is worth,
and in any case it could create new possible failure modes.  Simply
returning an empty string seems like the most appropriate fix.

Back-patch to all supported versions, even those before autovacuum, just
in case there's another way to provoke this crash.

src/backend/commands/variable.c

index b16c1d38f60b34786f81cec6b76be6b65f8c5fb0..b6bf4e1dc24a1d6c37062250d76a59c55da12f9a 100644 (file)
@@ -773,6 +773,10 @@ show_session_authorization(void)
        Oid                     savedoid;
        char       *endptr;
 
+       /* If session_authorization hasn't been set in this process, return "" */
+       if (value == NULL || value[0] == '\0')
+               return "";
+
        Assert(strspn(value, "x") == NAMEDATALEN &&
                   (value[NAMEDATALEN] == 'T' || value[NAMEDATALEN] == 'F'));