Skip to content

bound parameter buffer size before narrowing to SQLINTEGER#633

Merged
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:odbc-buffer-size-bounds
Apr 22, 2026
Merged

bound parameter buffer size before narrowing to SQLINTEGER#633
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:odbc-buffer-size-bounds

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Summary

Bounds ODBC-reported parameter sizes before converting to SQLINTEGER.

Problem

Parameter sizes are obtained as SQLULEN but later converted to SQLINTEGER.
The previous computation performed arithmetic and narrowing without enforcing
the SQLINTEGER range, which could produce invalid (overflowed) sizes for
out-of-range metadata.

Change

  • Compute sizes in size_t
  • Bound the character count using:
    max_chars = (INT_MAX - sizeof(CharT)) / sizeof(CharT)
  • Derive final byte size from the bounded value
  • Cast to SQLINTEGER only after ensuring it is in range
  • Apply the same logic consistently for both char and wchar_t paths

Behavior

  • Valid inputs: unchanged
  • Out-of-range inputs: values are bounded to a safe maximum instead of
    producing invalid sizes

Notes

  • Allocation pattern remains unchanged (palloc(paramValueSize + sizeof(CharT)))
  • No new control flow or error paths introduced
  • Change is localized to size computation only

@swebb2066 swebb2066 merged commit 1cf7c64 into apache:master Apr 22, 2026
17 checks passed
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.

2 participants