mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Return nulls honestly in aggregate "combine" functions.
numeric_combine() and several other state-combining functions for aggregates cheated for the case of both inputs being NULL: they returned a null pointer without bothering to mark it as a SQL NULL. This was harmless in the expected usage where the result would be passed to the same combine function or a related aggregate final function. But it's bad news from a security standpoint, because now that value can be passed to an internal-accepting function even if said function is strict. While a previous patch prevented such queries from being issued, it seems like good defense-in-depth to expend the few additional lines of code needed to do this properly. Comparable functions such as array_agg_combine() already do so. Reported-by: Amy Burnett (OpenAI Codex Security) Author: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 14 Security: CVE-2026-14680
This commit is contained in:
@@ -4830,7 +4830,15 @@ numeric_combine(PG_FUNCTION_ARGS)
|
||||
state2 = PG_ARGISNULL(1) ? NULL : (NumericAggState *) PG_GETARG_POINTER(1);
|
||||
|
||||
if (state2 == NULL)
|
||||
{
|
||||
/*
|
||||
* NULL state2 is easy, just return state1, which we know is already
|
||||
* in the agg_context
|
||||
*/
|
||||
if (state1 == NULL)
|
||||
PG_RETURN_NULL();
|
||||
PG_RETURN_POINTER(state1);
|
||||
}
|
||||
|
||||
/* manually copy all fields from state2 to state1 */
|
||||
if (state1 == NULL)
|
||||
@@ -4922,7 +4930,15 @@ numeric_avg_combine(PG_FUNCTION_ARGS)
|
||||
state2 = PG_ARGISNULL(1) ? NULL : (NumericAggState *) PG_GETARG_POINTER(1);
|
||||
|
||||
if (state2 == NULL)
|
||||
{
|
||||
/*
|
||||
* NULL state2 is easy, just return state1, which we know is already
|
||||
* in the agg_context
|
||||
*/
|
||||
if (state1 == NULL)
|
||||
PG_RETURN_NULL();
|
||||
PG_RETURN_POINTER(state1);
|
||||
}
|
||||
|
||||
/* manually copy all fields from state2 to state1 */
|
||||
if (state1 == NULL)
|
||||
@@ -5445,7 +5461,15 @@ numeric_poly_combine(PG_FUNCTION_ARGS)
|
||||
state2 = PG_ARGISNULL(1) ? NULL : (PolyNumAggState *) PG_GETARG_POINTER(1);
|
||||
|
||||
if (state2 == NULL)
|
||||
{
|
||||
/*
|
||||
* NULL state2 is easy, just return state1, which we know is already
|
||||
* in the agg_context
|
||||
*/
|
||||
if (state1 == NULL)
|
||||
PG_RETURN_NULL();
|
||||
PG_RETURN_POINTER(state1);
|
||||
}
|
||||
|
||||
/* manually copy all fields from state2 to state1 */
|
||||
if (state1 == NULL)
|
||||
@@ -5672,7 +5696,15 @@ int8_avg_combine(PG_FUNCTION_ARGS)
|
||||
state2 = PG_ARGISNULL(1) ? NULL : (PolyNumAggState *) PG_GETARG_POINTER(1);
|
||||
|
||||
if (state2 == NULL)
|
||||
{
|
||||
/*
|
||||
* NULL state2 is easy, just return state1, which we know is already
|
||||
* in the agg_context
|
||||
*/
|
||||
if (state1 == NULL)
|
||||
PG_RETURN_NULL();
|
||||
PG_RETURN_POINTER(state1);
|
||||
}
|
||||
|
||||
/* manually copy all fields from state2 to state1 */
|
||||
if (state1 == NULL)
|
||||
|
||||
Reference in New Issue
Block a user