Skip to content

Zero-initialize parent_cpstate in analyze_cypher#2423

Merged
jrgemignani merged 1 commit intoapache:masterfrom
hari90:claude/fix-cypher-parser-memory-J8LsQ
May 4, 2026
Merged

Zero-initialize parent_cpstate in analyze_cypher#2423
jrgemignani merged 1 commit intoapache:masterfrom
hari90:claude/fix-cypher-parser-memory-J8LsQ

Conversation

@hari90
Copy link
Copy Markdown
Contributor

@hari90 hari90 commented May 2, 2026

cypher_parsestate parent_cpstate is declared on the stack in analyze_cypher() and only pstate, graph_name, and params are explicitly set before it is passed to make_cypher_parsestate(). The latter reads parent_cpstate->subquery_where_flag (and other fields) in cypher_parse_node.c, which leaves them with indeterminate values. Yugabyte UBSan flagged the garbage bool (value 8) and aborted the backend.

Use MemSet to zero the struct before populating the explicit fields so all remaining members start with a defined value.

cypher_parsestate parent_cpstate is declared on the stack in
analyze_cypher() and only pstate is explicitly set before it is passed
to make_cypher_parsestate(). The latter reads
parent_cpstate->subquery_where_flag (and other fields) in
cypher_parse_node.c, which leaves them with indeterminate values. UBSan
flagged the garbage bool (value 8) and aborted the backend.

Use MemSet to zero the struct before populating pstate so all remaining
members start with a defined value.
@hari90 hari90 force-pushed the claude/fix-cypher-parser-memory-J8LsQ branch from c6a9b79 to e30e73c Compare May 3, 2026 05:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an uninitialized-stack-memory bug in the Cypher analysis path by ensuring the temporary cypher_parsestate wrapper passed into make_cypher_parsestate() starts from a fully defined state, preventing UBSan failures and undefined behavior.

Changes:

  • Zero-initialize parent_cpstate with MemSet() in analyze_cypher() before setting its explicitly required fields.
  • Remove now-redundant explicit NULL assignments for members covered by the zero-initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jrgemignani jrgemignani merged commit e9ef30b into apache:master May 4, 2026
10 checks passed
@hari90 hari90 deleted the claude/fix-cypher-parser-memory-J8LsQ branch May 4, 2026 18:49
@hari90
Copy link
Copy Markdown
Contributor Author

hari90 commented May 4, 2026

Thank you

hari90 added a commit to yugabyte/yugabyte-db that referenced this pull request May 4, 2026
## Summary

Fixes #31404. Zero-initialize the stack-allocated `parent_cpstate` in
`analyze_cypher()` before passing it to `make_cypher_parsestate()`.

The struct previously had only `pstate`, `graph_name`, and `params` set,
leaving `subquery_where_flag` (and other fields) as uninitialized stack
memory. `make_cypher_parsestate()` reads
`parent_cpstate->subquery_where_flag`
directly (`cypher_parse_node.c:62`), so under UndefinedBehaviorSanitizer
the
load aborts the backend whenever the stack byte is something other than
0 or
1. The first `cypher()` call in the asan/ubsan build was reliably
crashing
with:

```
runtime error: load of value 8, which is not a valid value for type 'bool'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior cypher_parse_node.c:62:56
```

This is a latent upstream Apache AGE bug; the file is a verbatim subtree
import. Worth reporting upstream as well.

The redundant `graph_name = NULL`/`params = NULL` assignments are
removed
since `memset` already zeros them.

## Test plan

- `./yb_build.sh asan --java-test
'org.yb.pgsql.TestPgRegressThirdPartyExtensionsMage#schedule'`
  was failing on `yb.orig.basic` before this change and passes with it.

Upstream fix apache/age#2423

---

[CSI](<https://csiweb.dev.yugabyte.com/pull/31405/>)
hari90 added a commit to yugabyte/yugabyte-db that referenced this pull request May 5, 2026
…#31405) (#31423)

## Summary

Fixes #31404. Zero-initialize the stack-allocated `parent_cpstate` in
`analyze_cypher()` before passing it to `make_cypher_parsestate()`.

The struct previously had only `pstate`, `graph_name`, and `params` set,
leaving `subquery_where_flag` (and other fields) as uninitialized stack
memory. `make_cypher_parsestate()` reads
`parent_cpstate->subquery_where_flag`
directly (`cypher_parse_node.c:62`), so under UndefinedBehaviorSanitizer
the
load aborts the backend whenever the stack byte is something other than
0 or
1. The first `cypher()` call in the asan/ubsan build was reliably
crashing
with:

```
runtime error: load of value 8, which is not a valid value for type 'bool'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior cypher_parse_node.c:62:56
```

This is a latent upstream Apache AGE bug; the file is a verbatim subtree
import. Worth reporting upstream as well.

The redundant `graph_name = NULL`/`params = NULL` assignments are
removed
since `memset` already zeros them.

Original commit: 154e1a6 / #31405

## Test plan

- `./yb_build.sh asan --java-test
'org.yb.pgsql.TestPgRegressThirdPartyExtensionsMage#schedule'`
  was failing on `yb.orig.basic` before this change and passes with it.

Upstream fix apache/age#2423

---

[CSI](<https://csiweb.dev.yugabyte.com/pull/31423/>)
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.

3 participants