Skip to content

Fix backend crashes on NULL arguments in stddev final functions and a… - #2613

Open
bilalkah wants to merge 1 commit into
apache:masterfrom
bilalkah:fix-null-arg-crashes
Open

bilalkah wants to merge 1 commit into
apache:masterfrom
bilalkah:fix-null-arg-crashes

Conversation

@bilalkah

Copy link
Copy Markdown

These calls crash the backend with SIGSEGV, which makes the postmaster reinitialize and drops every other session:

SELECT ag_catalog.age_float8_stddev_samp_aggfinalfn(NULL);
SELECT ag_catalog.age_float8_stddev_pop_aggfinalfn(NULL);
-- and the 8 argument form of age_vle() with NULL as the last argument

The two stddev final functions are not STRICT, but they pass the argument straight to float8_stddev_samp() / float8_stddev_pop(), which don't check for NULL. The stDev() / stDevP() aggregates never pass a NULL state, so only direct calls hit this. They now return NULL for a NULL state, like a STRICT function would.

age_vle() reads its 8th argument (the VLE grammar node id) without a NULL check. It is now part of the existing check for required arguments and raises "age_vle: invalid NULL argument passed".

I found these by calling every non-STRICT function of the extension with NULL arguments (all NULL, and one NULL at a time). Besides these, only age_create_barbell_graph() with a NULL node label crashed, and that is already fixed on master in #2521. Reproduced on 1.7.0, 1.8.0 and master with PostgreSQL 18.

Regression tests are added to expr and cypher_vle. installcheck passes.

…ge_vle

age_float8_stddev_samp_aggfinalfn() and age_float8_stddev_pop_aggfinalfn()
are not STRICT, but they pass their argument straight to PostgreSQL's
float8_stddev_samp() / float8_stddev_pop(), which do not check for NULL.
A direct call with NULL crashes the backend with SIGSEGV:

    SELECT ag_catalog.age_float8_stddev_samp_aggfinalfn(NULL);
    SELECT ag_catalog.age_float8_stddev_pop_aggfinalfn(NULL);

The stDev() / stDevP() aggregates never pass a NULL state (initcond is
{0,0,0} and the transition function is STRICT), so only direct calls are
affected. Return NULL for a NULL state, as a STRICT function would.

The 8 argument form of age_vle() reads its last argument, the VLE grammar
node id, without a NULL check, so passing NULL there crashes the backend
the same way. Add it to the existing check for required arguments, which
raises "age_vle: invalid NULL argument passed".

A SIGSEGV in one backend makes the postmaster reinitialize and drops every
other session on the instance.

Found by calling every non-STRICT function of the extension with NULL
arguments (all NULL, and one NULL at a time). Besides these three, only
age_create_barbell_graph() with a NULL node label crashed, and that is
already fixed on master (apache#2521). Reproduced on 1.7.0, 1.8.0 and master
with PostgreSQL 18.
@bilalkah

Copy link
Copy Markdown
Author

Hi @jrgemignani @MuhammadTahaNaveed could you take a look when you have time?

Small fix: NULL guards for age_float8_stddev_samp_aggfinalfn / age_float8_stddev_pop_aggfinalfn and the 8-arg age_vle (grammar node id). All three segfault the backend on a direct call with NULL, reproduced on 1.7.0, 1.8.0 and master. Regression tests added, installcheck passes.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant