You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Named-bind query escaping can overrun its heap buffer #1554
master at b21cd664004bc4383edfb7944712599818d635af
Current Behavior
The two get_parameter_description() query-building paths in src/interfaces/libpq/ivy-exec.c allocate 2 * query_length bytes for an escaped query, duplicate every single quote, and then append a NUL terminator.
For an input consisting entirely of single quotes, the escaped bytes consume the whole allocation and the terminator is written one byte past the heap buffer. The Ivyreplacenamebindtoposition2() path also has no empty-query guard, so it can write a terminator through a zero-length allocation.
Affected code:
Ivyreplacenamebindtoposition() around lines 3791-3811
Ivyreplacenamebindtoposition2() around lines 4078-4099
Expected behavior/code
The escaped-query buffer must include space for the terminating NUL and reject allocation-size overflow. Empty input must also produce a valid one-byte empty string buffer.
Step to reproduce
Build or run the affected path with AddressSanitizer and prepare a query whose bytes are all single quotes, for example ''.
The current size calculation allocates four bytes, writes four escaped quote bytes, and then writes a fifth NUL byte.
Additional context that can be helpful for identifying the problem
Both functions contain the same manual escaping loop, so both entry points require the same boundary correction. This issue is limited to the allocation boundary; changing the escaping or query semantics is not necessary.
Activity
jiaoshuntian commentedon Aug 12, 2026
Does the same issue also exist in
get_hostvariables()insrc/bin/psql/common.c?Aias00 commentedon Aug 12, 2026
Yes, the same issue exists in get_hostvariables() in src/bin/psql/common.c.
Fix heap buffer overrun in named-bind query escaping