postgresql/src/bin
Tom Lane 5b64368742 Fix incautious handling of possibly-miscoded strings in client code.
An incorrectly-encoded multibyte character near the end of a string
could cause various processing loops to run past the string's
terminating NUL, with results ranging from no detectable issue to
a program crash, depending on what happens to be in the following
memory.

This isn't an issue in the server, because we take care to verify
the encoding of strings before doing any interesting processing
on them.  However, that lack of care leaked into client-side code
which shouldn't assume that anyone has validated the encoding of
its input.

Although this is certainly a bug worth fixing, the PG security team
elected not to regard it as a security issue, primarily because
any untrusted text should be sanitized by PQescapeLiteral or
the like before being incorporated into a SQL or psql command.
(If an app fails to do so, the same technique can be used to
cause SQL injection, with probably much more dire consequences
than a mere client-program crash.)  Those functions were already
made proof against this class of problem, cf CVE-2006-2313.

To fix, invent PQmblenBounded() which is like PQmblen() except it
won't return more than the number of bytes remaining in the string.
In HEAD we can make this a new libpq function, as PQmblen() is.
It seems imprudent to change libpq's API in stable branches though,
so in the back branches define PQmblenBounded as a macro in the files
that need it.  (Note that just changing PQmblen's behavior would not
be a good idea; notably, it would completely break the escaping
functions' defense against this exact problem.  So we just want a
version for those callers that don't have any better way of handling
this issue.)

Per private report from houjingyi.  Back-patch to all supported branches.
2021-06-07 14:15:25 -04:00
..
initdb Translation updates 2021-05-10 14:32:18 +02:00
pg_archivecleanup Translation updates 2021-05-10 14:32:18 +02:00
pg_basebackup Translation updates 2020-11-09 12:34:05 +01:00
pg_checksums Translation updates 2021-05-10 14:32:18 +02:00
pg_config Translation updates 2021-05-10 14:32:18 +02:00
pg_controldata Translation updates 2021-05-10 14:32:18 +02:00
pg_ctl Translation updates 2021-05-10 14:32:18 +02:00
pg_dump Translation updates 2021-05-10 14:32:18 +02:00
pg_resetwal Translation updates 2021-05-10 14:32:18 +02:00
pg_rewind Translation updates 2021-02-08 17:41:32 +01:00
pg_test_fsync Translation updates 2021-05-10 14:32:18 +02:00
pg_test_timing Translation updates 2021-05-10 14:32:18 +02:00
pg_upgrade Clean up cpluspluscheck violation. 2021-05-20 13:03:08 -04:00
pg_verifybackup Translation updates 2021-02-08 17:41:32 +01:00
pg_waldump pg_waldump: Fix bug in per-record statistics. 2021-03-23 09:54:38 +09:00
pgbench pgbench: Remove dead code 2021-01-28 12:53:10 -03:00
pgevent Remove libpq.rc, use win32ver.rc for libpq 2020-01-15 15:06:12 +01:00
psql Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
scripts Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
Makefile Rename pg_validatebackup to pg_verifybackup. 2020-04-12 11:26:05 -04:00