Fix malformed Bind packets when client provides a single parameter format#5282
Fix malformed Bind packets when client provides a single parameter format#5282renecannao merged 3 commits intov3.0from
Conversation
…ovided PostgreSQL allows a Bind message to specify a single parameter format (num_param_formats = 1), which applies to all parameters. libpq, however, always expects a format entry per parameter and previously sent uninitialized values for the remaining parameters when only one format was specified. This caused ProxySQL to forward malformed Bind packets to backend. ProxySQL now detects this case and propagates the single provided parameter format to all parameters, matching PostgreSQL semantics.
Summary of ChangesHello @rahim-kanji, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug in ProxySQL's PostgreSQL extended query protocol implementation. It specifically addresses an issue where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a bug in handling PostgreSQL Bind packets where a single parameter format was not being correctly applied to all parameters. The core logic change in PgSQL_Connection.cpp is sound and correctly implements the protocol specification by expanding the format list. The accompanying new regression test is comprehensive and covers the fix well. I have a few minor suggestions to improve code style and maintainability in both the application and test code.
| test_null_parameter_handling(); | ||
|
|
||
| return exit_status(); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Pull request overview
This PR fixes a protocol compliance issue in ProxySQL's handling of PostgreSQL BIND messages. When a client provides a single parameter format (num_param_formats=1) for multiple parameters, ProxySQL previously forwarded uninitialized values, resulting in malformed packets. The fix ensures ProxySQL correctly expands the single format to all parameters before forwarding to libpq, which expects an explicit format for each parameter.
- Adds format normalization logic in
PgSQL_Connection.cppto expand single format to all parameters - Introduces comprehensive test suite with 7 test cases covering all protocol scenarios
- Adds test client helpers (
bindStatementExandbindStatementSingleFormat) for explicit format control
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/PgSQL_Connection.cpp | Implements the core fix: expands single parameter format to all parameters and validates format counts |
| test/tap/tests/pg_lite_client.h | Adds new bind method signatures for explicit format control in tests |
| test/tap/tests/pg_lite_client.cpp | Implements new bind methods and updates existing bindStatement to optimize format encoding |
| test/tap/tests/pgsql-reg_test_5273_bind_parameter_format-t.cpp | New comprehensive test suite covering all protocol scenarios |
| test/tap/tests/pgsql-extended_query_protocol_test-t.cpp | Moves plan() call before cl.getEnv() for proper test structure |
| test/tap/tests/Makefile | Adds build target for new test |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... 📒 Files selected for processing (7)
Tip You can validate your CodeRabbit configuration file in your editor.If your editor has YAML language server, you can enable auto-completion and validation by adding ✨ Finishing touches
Comment |



Background
In the PostgreSQL extended query protocol, the Bind message supports the
following semantics for parameter formats:
num_param_formats = 0: all parameters use the default text formatnum_param_formats = 1: a single format applies to all parametersnum_param_formats = num_params: each parameter has an explicit formatAny other combination is invalid.
While PostgreSQL correctly applies the single provided format to all parameters,
ProxySQL previously did not replicate this behavior.
Issue
When a client sent a Bind message with:
ProxySQL forwarded uninitialized (garbage) values for the remaining parameter
formats (
libpqhas a limitation where it expects a parameter format entry for eachparameter). This resulted in malformed Bind packets and protocol errors.
Fix
This PR updates ProxySQL’s Bind handling to match PostgreSQL behavior:
format to all parameters.
This prevents malformed packets and ensures compatibility with libpq and compliance with the PostgreSQL specification.
Impact
No behavior change occurs for valid cases where all parameter formats are
explicitly provided.
Closes #5273
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.