Switch order of tests to avoid possible Assert failure for
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Jun 2009 18:15:04 +0000 (18:15 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Jun 2009 18:15:04 +0000 (18:15 +0000)
"array_agg_finalfn(null)".  We should modify pg_proc entries to prevent this
query from being accepted, but let's just make the function itself secure too.
Per my note of today.

src/backend/utils/adt/array_userfuncs.c

index 13a409d0c59744949cf85d31d5fddc1f9b744c90..bdc4433891a6bc91253da0a76f280ad375b6b44d 100644 (file)
@@ -520,14 +520,19 @@ array_agg_finalfn(PG_FUNCTION_ARGS)
        int                     dims[1];
        int                     lbs[1];
 
+       /*
+        * Test for null before Asserting we are in right context.  This is
+        * to avoid possible Assert failure in 8.4beta installations, where
+        * it is possible for users to create NULL constants of type internal.
+        */
+       if (PG_ARGISNULL(0))
+               PG_RETURN_NULL();   /* returns null iff no input values */
+
        /* cannot be called directly because of internal-type argument */
        Assert(fcinfo->context &&
                   (IsA(fcinfo->context, AggState) ||
                        IsA(fcinfo->context, WindowAggState)));
 
-       if (PG_ARGISNULL(0))
-               PG_RETURN_NULL();   /* returns null iff no input values */
-
        state = (ArrayBuildState *) PG_GETARG_POINTER(0);
 
        dims[0] = state->nelems;