Skip to content

Fix ? operator crash on an agtype null left operand - #2589

Open
akashchamp wants to merge 1 commit into
apache:masterfrom
akashchamp:fix-exists-null-operand
Open

akashchamp wants to merge 1 commit into
apache:masterfrom
akashchamp:fix-exists-null-operand

Conversation

@akashchamp

Copy link
Copy Markdown

Fixes #2562.

SELECT 'null'::agtype ? '"a"'::agtype; crashes the backend with SIGSEGV. In agtype_exists_agtype(), extract_entity_properties(agt, false) returns NULL for an agtype null scalar (and for an entity with null properties), and that NULL goes straight into agtype_value_to_agtype().

The fix checks for NULL and returns false, which is what ? already returns for other non-container scalars like '1' or '"s"'. I left ?| / ?& alone since they already raise a clean error for this input. I also added two cases to regress/sql/jsonb_operators.sql.

Testing, against PostgreSQL 18.6 built from source:

  • Before the fix, the query from the issue kills the backend ("terminated by signal 11: Segmentation fault"). With the new test cases and no C change, make installcheck crashes in jsonb_operators (17 of 44 failed).
  • With the fix, both cases return f. '1' ? '"a"' still returns f, and the vertex and object cases still return t.
  • make installcheck: all 44 tests passed.

For a scalar left operand, agtype_exists_agtype() passes the result of
extract_entity_properties() straight to agtype_value_to_agtype(). For an
agtype null (or an entity whose properties are null) that result is NULL,
so the backend dereferences a NULL pointer and the postmaster restarts:

    SELECT 'null'::agtype ? '"a"'::agtype;

Return false when there are no properties to search, the same answer the
operator already gives for other non-container scalars such as '1' or
'"s"'. Add regression cases to jsonb_operators.

Fixes apache#2562
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.

The ? (exists) operator crashes the server (SIGSEGV) on an agtype-null left operand

1 participant