Skip to content

Fix backend crash on non-string SET search_path arguments - #68

Merged
darold merged 1 commit into
darold:masterfrom
virendercse:fix-search-path-non-string
Oct 13, 2026
Merged

darold merged 1 commit into
darold:masterfrom
virendercse:fix-search-path-non-string

Conversation

@virendercse

Copy link
Copy Markdown
Contributor

Summary

When pgtt is loaded in a session, executing SET search_path = <integer>; (e.g., SET search_path = 123;) crashes the backend process with SIGSEGV (or FailedAssertion in assert-enabled builds).

Root Cause

PostgreSQL's grammar accepts var_value: opt_boolean_or_string | NumericOnly for SET statements, so SET search_path = 123; produces an A_Const node whose value tag is T_Integer rather than T_String.

In gtt_check_command(), the T_VariableSetStmt handler unconditionally called strVal(&con->val) on every element of stmt->args:

  • PG 15+: Integer ({ NodeTag type; int ival; }) only writes the first 8 bytes of union ValUnion, leaving String.sval (at offset 8 on 64-bit platforms) as NULL in release builds (strcmp(NULL, ...) segfaults) or tripping castNode(String, ...) in assert-enabled builds.
  • PG < 15: Value's union ValUnion overlays int ival and char *str at the same offset, so strVal(&con->val) reads the integer as a pointer and strcmp() segfaults.

Fix

  • Guard the loop in gtt_check_command() with IsA(arg, A_Const) and IsA(&con->val, String) before calling strVal(&con->val).
  • Look up get_namespace_name(pgtt_namespace_oid) once before the loop and check for NULL.
  • Add a regression test in test/sql/13_searchpath.sql.

Fixes #67

@darold
darold merged commit e9c1e58 into darold:master Oct 13, 2026
7 checks passed
@darold

darold commented Oct 13, 2026

Copy link
Copy Markdown
Owner

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.

Segfault when running SET search_path = <integer>

2 participants