Skip to content

Guard against NULL outbind entry in DO statement parameter setup - #1619

Closed
Aias00 wants to merge 1 commit into
IvorySQL:masterfrom
Aias00:fix/ivy-exec-outbind-null-1617
Closed

Guard against NULL outbind entry in DO statement parameter setup#1619
Aias00 wants to merge 1 commit into
IvorySQL:masterfrom
Aias00:fix/ivy-exec-outbind-null-1617

Conversation

@Aias00

@Aias00 Aias00 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1617: in the DO-statement parameter setup of IvyStmtExecute (src/interfaces/libpq/ivy-exec.c), the inner loop searches outbind for info->position == i + 1 and then dereferences info unconditionally. If the caller bound non-contiguous positions (e.g. 1 and 3, skipping 2), info is NULL and info->dtype crashes the client process.

The fix reports "outbind position not found" and cleans up (paramTypes + query_buf) before returning 0, matching the error style of the same function.

Test plan

  • make -C src/interfaces/libpq ivy-exec.o compiles cleanly.
  • Manual: bind positions 1 and 3 of a 3-placeholder statement and execute a DO statement — the client now gets an error instead of crashing.

Summary by CodeRabbit

  • Bug Fixes
    • Added validation for missing output parameter bindings.
    • Improved error handling to prevent failures when an output parameter has no corresponding bind entry.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: dbcae688-a4c3-46a3-97e5-a8c287082505

📥 Commits

Reviewing files that changed from the base of the PR and between c3529ba and a80109d.

📒 Files selected for processing (1)
  • src/interfaces/libpq/ivy-exec.c

📝 Walkthrough

Walkthrough

IvyHandleDostmt now detects missing OUT-bind entries before dereferencing them. It reports an error, releases allocated resources, and returns failure.

Changes

OUT-bind validation

Layer / File(s) Summary
Validate missing OUT-bind positions
src/interfaces/libpq/ivy-exec.c
IvyHandleDostmt checks for a matching OUT-bind entry. When none exists, it records an error, frees paramTypes, destroys query_buf, and returns 0.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to a8010

This localized fix prevents a client crash when DO-statement parameter positions are non-contiguous and returns an error instead; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the NULL outbind-entry guard added for DO statement parameter setup.
Linked Issues check ✅ Passed The change detects missing outbind entries, reports an error, cleans up resources, and prevents the NULL dereference required by issue #1617.
Out of Scope Changes check ✅ Passed The changes are limited to validation and cleanup for the linked NULL dereference issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

When outbind positions are not contiguous, the inner lookup loop ends
with info == NULL and the subsequent info->dtype dereference crashes
the client. Report an error and clean up instead.

Closes IvorySQL#1617

Signed-off-by: liuhongyu <liuhongyu@apache.org>
@Aias00
Aias00 force-pushed the fix/ivy-exec-outbind-null-1617 branch from a80109d to 23be139 Compare August 17, 2026 03:01
@NotHimmel

Copy link
Copy Markdown
Collaborator

Thanks for the report and PR, could you confirm how it was found and provide a concrete reproduction?

@Aias00

Aias00 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing per the discussion in #1617 - the NULL deref is real but only reachable when a C client binds non-contiguous positions via IvyBindByPos (an unusual pattern no in-tree code produces); impact is a client-process crash only. Happy to resubmit the one-line guard as a focused PR if a maintainer wants it.

@Aias00 Aias00 closed this Aug 17, 2026
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.

ivy-exec: NULL dereference when outbind positions are not contiguous

2 participants