postgresql/src/common
Michael Paquier de343812b9 Fix buffer overrun in unicode string normalization with empty input
PostgreSQL 13 and newer versions are directly impacted by that through
the SQL function normalize(), which would cause a call of this function
to write one byte past its allocation if using in input an empty
string after recomposing the string with NFC and NFKC.  Older versions
(v10~v12) are not directly affected by this problem as the only code
path using normalization is SASLprep in SCRAM authentication that
forbids the case of an empty string, but let's make the code more robust
anyway there so as any out-of-core callers of this function are covered.

The solution chosen to fix this issue is simple, with the addition of a
fast-exit path if the decomposed string is found as empty.  This would
only happen for an empty string as at its lowest level a codepoint would
be decomposed as itself if it has no entry in the decomposition table or
if it has a decomposition size of 0.

Some tests are added to cover this issue in v13~.  Note that an empty
string has always been considered as normalized (grammar "IS NF[K]{C,D}
NORMALIZED", through the SQL function is_normalized()) for all the
operations allowed (NFC, NFD, NFKC and NFKD) since this feature has been
introduced as of 2991ac5.  This behavior is unchanged but some tests are
added in v13~ to check after that.

I have also checked "make normalization-check" in src/common/unicode/,
while on it (works in 13~, and breaks in older stable branches
independently of this commit).

The release notes should just mention this commit for v13~.

Reported-by: Matthijs van der Vleuten
Discussion: https://postgr.es/m/17277-0c527a373794e802@postgresql.org
Backpatch-through: 10
2021-11-11 15:01:57 +09:00
..
unicode Make script output more pgindent compatible 2019-06-24 22:50:56 +02:00
.gitignore Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
base64.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
config_info.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
controldata_utils.c Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
d2s.c Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
d2s_full_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
d2s_intrinsics.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
digit_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
exec.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
f2s.c Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
fe_memutils.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
file_perm.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
file_utils.c Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
ip.c Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
keywords.c Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
kwlookup.c Use perfect hashing, instead of binary search, for keyword lookup. 2019-01-09 19:47:46 -05:00
link-canary.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
logging.c Fix command-line colorization on Windows with VT100-compatible environments 2020-03-02 15:46:24 +09:00
Makefile Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
md5.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
pg_lzcompress.c Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
pgfnames.c Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
psprintf.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
relpath.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
restricted_token.c Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
rmtree.c Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
ryu_common.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
saslprep.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
scram-common.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
sha2.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
sha2_openssl.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
string.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
unicode_norm.c Fix buffer overrun in unicode string normalization with empty input 2021-11-11 15:01:57 +09:00
username.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
wait_error.c Update copyright for 2019 2019-01-02 12:44:25 -05:00