Skip to content

CI: run the test_escape TAP test - #2242

Open
tuhaihe wants to merge 6 commits into
apache:mainfrom
tuhaihe:ci-test-escape
Open

tuhaihe wants to merge 6 commits into
apache:mainfrom
tuhaihe:ci-test-escape

Conversation

@tuhaihe

@tuhaihe tuhaihe commented Nov 4, 2026

Copy link
Copy Markdown
Member

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


tuhaihe and others added 6 commits November 4, 2026 16:39
The test steps join make_configs with spaces and then split the result
on spaces.  An entry that contains a space, such as "dir:all
installcheck", becomes two configurations, and the second one has no
directory.

Join the entries with newlines and read one entry per line instead.
All current entries give the same configurations as before.  apache#2237
has the same change.

Assisted-by: Claude Code
CI does not run the TAP test in src/test/modules/test_escape, so nobody
sees when the escaping functions of libpq and fe_utils break.

Add an ic-test-escape test job that runs it on Rocky 8, 9 and 10.  The
build does not make the test_escape program, and installcheck does not
make it either, so the job runs "all installcheck".

Assisted-by: Claude Code
In 5dc1e42 I fixed bugs in various escape functions, unfortunately as part
of that I introduced a new bug in PQescapeLiteral()/PQescapeIdentifier(). The
bug is that I made PQescapeInternal() just use strlen(), rather than taking
the specified input length into account.

That's bad, because it can lead to including input that wasn't intended to be
included (in case len is shorter than null termination of the string) and
because it can lead to reading invalid memory if the input string is not null
terminated.

Expand test_escape to this kind of bug:

a) for escape functions with length support, append data that should not be
   escaped and check that it is not

b) add valgrind requests to detect access of bytes that should not be touched

Author: Tom Lane <tgl@sss.pgh.pa.us>
Author: Andres Freund <andres@anarazel.de
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/Z64jD3u46gObCo1p@pryzbyj2023
Backpatch: 13
(cherry picked from commit 111f4dd)

Cloudberry: the REL_16_9 merge lost the fe-exec.c part of this commit,
so PQescapeInternal() compared the verified length with strlen().  Only
that line is applied here.  28538ac already uses strnlen() for
input_len, and test_escape.c already has the test changes.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally.  This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42.

While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string.  This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.

This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.

Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
(cherry picked from commit 991a60a)

Cloudberry: the REL_16_9 merge lost this commit.
PQescapeStringInternal() still had an older way to report errors, so it
is taken as it is in this commit.
With GB18030 as source encoding, applications could crash the server via
SQL functions convert() or convert_from().  Applications themselves
could crash after passing unterminated GB18030 input to libpq functions
PQescapeLiteral(), PQescapeIdentifier(), PQescapeStringConn(), or
PQescapeString().  Extension code could crash by passing unterminated
GB18030 input to jsonapi.h functions.  All those functions have been
intended to handle untrusted, unterminated input safely.

A crash required allocating the input such that the last byte of the
allocation was the last byte of a virtual memory page.  Some malloc()
implementations take measures against that, making the SIGSEGV hard to
reach.  Back-patch to v13 (all supported versions).

Author: Noah Misch <noah@leadboat.com>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Backpatch-through: 13
Security: CVE-2025-4207
(cherry picked from commit d126494)

Cloudberry: the REL_16_9 merge lost the PQescapeStringInternal() part
of this commit.  Only that part is applied here.  The other files
already have the rest.
Coverity complained that we weren't doing that, and it's right.

This fix just makes fmtIdEnc() honor the general convention that OOM
causes a PQExpBuffer to become marked "broken", without any immediate
error.  In the pretty-unlikely case that we actually did hit OOM here,
the end result would be to return an empty string to the caller,
probably resulting in invalid SQL syntax in an issued command (if
nothing else went wrong, which is even more unlikely).  It's tempting
to throw an "out of memory" error if the buffer becomes broken, but
there's not a lot of point in doing that only here and not in hundreds
of other PQExpBuffer-using places in pg_dump and similar callers.
The whole issue could do with some non-time-crunched redesign, perhaps.

This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.

(cherry picked from commit 644b7d6)

Cloudberry: the REL_16_9 merge lost this commit.
@tuhaihe tuhaihe moved this to In Progress in Merge postgres 16 Nov 4, 2026
@yjhjstz

yjhjstz commented Nov 4, 2026

Copy link
Copy Markdown
Member

we can gather test_escape, pg_dump etc tap test all together into one CI pipeline.

@tuhaihe

tuhaihe commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

we can gather test_escape, pg_dump etc tap test all together into one CI pipeline.

Will do. These separate PRs target the failing tests; once all are fixed, I’ll consolidate them into one.

@tuhaihe

tuhaihe commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

Note: This separate PR addresses the failing test and is easy to review; once fixed, I’ll consolidate the similar tests into one.

@leborchuk leborchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants