pgsql: Add test of various escape functions

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add test of various escape functions
Date: 2025-02-10 15:09:49
Message-ID: E1thVPw-006NyG-RZ@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add test of various escape functions

As highlighted by the prior commit, writing correct escape functions is less
trivial than one might hope.

This test module tries to verify that different escaping functions behave
reasonably. It e.g. tests:

- Invalidly encoded input to an escape function leads to invalidly encoded
output

- Trailing incomplete multi-byte characters are handled sensibly

- Escaped strings are parsed as single statement by psql's parser (which
derives from the backend parser)

There are further tests that would be good to add. But even in the current
state it was rather useful for writing the fix in the prior commit.

Reviewed-by: Noah Misch <noah(at)leadboat(dot)com>
Backpatch-through: 13
Security: CVE-2025-1094

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/de4b92f3332b7ea3373ae7bad0d790473b3665e6

Modified Files
--------------
src/test/modules/Makefile | 1 +
src/test/modules/test_escape/.gitignore | 2 +
src/test/modules/test_escape/Makefile | 27 +
src/test/modules/test_escape/t/001_test_escape.pl | 53 ++
src/test/modules/test_escape/test_escape.c | 803 ++++++++++++++++++++++
src/tools/msvc/Mkvcbuild.pm | 2 +-
src/tools/pgindent/typedefs.list | 3 +
7 files changed, 890 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2025-02-10 17:30:44 pgsql: Fix type in test_escape test
Previous Message Andres Freund 2025-02-10 15:09:48 pgsql: Specify the encoding of input to fmtId()