From: Bruce Momjian Date: Mon, 2 Feb 2015 15:00:44 +0000 (-0500) Subject: to_char(): prevent accesses beyond the allocated buffer X-Git-Tag: REL9_5_ALPHA1~831 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0150ab567bcf5e5913e2b62a1678f84cc272441f;p=postgresql to_char(): prevent accesses beyond the allocated buffer Previously very long field masks for floats could access memory beyond the existing buffer allocated to hold the result. Reported by Andres Freund and Peter Geoghegan. Backpatch to all supported versions. Security: CVE-2015-0241 --- diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index f39de1f232..4bc9e1c281 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -4428,7 +4428,9 @@ NUM_numpart_to_char(NUMProc *Np, int id) Np->num_in = TRUE; } } - ++Np->number_p; + /* do no exceed string length */ + if (*Np->number_p) + ++Np->number_p; } end = Np->num_count + (Np->out_pre_spaces ? 1 : 0) + (IS_DECIMAL(Np->Num) ? 1 : 0);