postgres.git / summary / log / commit / refs

commit    46aaec4c0e6d90e9f074982feb43efd4b3c42a78
Author:   Jacob Champion <jchampion@postgresql.org>
Date:     Fri Feb 06 19:08:59 2026 +0000
First released in: 14.21, 15.16, 16.12, 17.8

    Protect against small overread in SASLprep validation
    
    (This is a cherry-pick of 390b3cbbb, which I hadn't realized wasn't
    backpatched. It was originally reported to security@ and determined not
    to be a vulnerability; thanks to Stanislav Osipov for noticing the
    omission in the back branches.)
    
    In case of torn UTF8 in the input data we might end up going
    past the end of the string since we don't account for length.
    While validation won't be performed on a sequence with a NULL
    byte it's better to avoid going past the end to beging with.
    Fix by taking the length into consideration.
    
    Reported-by: Stanislav Osipov <stasos24@gmail.com>
    Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
    Discussion: https://postgr.es/m/CAOYmi+mTnmM172g=_+Yvc47hzzeAsYPy2C4UBY3HK9p-AXNV0g@mail.gmail.com
    Backpatch-through: 14


src/common/saslprep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/saslprep.c b/src/common/saslprep.c index e7e909a0c87..80b9edb3968 100644 --- a/src/common/saslprep.c +++ b/src/common/saslprep.c @@ -1009,15 +1009,17 @@ pg_utf8_string_len(const char *source) const unsigned char *p = (const unsigned char *) source; int l; int num_chars = 0; + size_t len = strlen(source); - while (*p) + while (len) { l = pg_utf_mblen(p); - if (!pg_utf8_islegal(p, l)) + if (len < l || !pg_utf8_islegal(p, l)) return -1; p += l; + len -= l; num_chars++; } [parent: 977a17a3eb33]