Hello Guillaume,

On Mon, Nov 02, 2026 at 03:20:27PM +0100, Guillaume Lelarge wrote:
> On 02/11/2026 10:30, Bertrand Drouvot wrote:
> > As far the patch, a few comments:
> > 
> > === 1
> > 
> > +               /* copy the "n_decimals" rest */
> > +               for (int j = 1; j <= n_decimals ; j++)
> > +               {
> > +                       new_str[new_str_pos++] = my_str[i++];
> > +               }
> > 
> > This can read past my_str and write past new_str. For example:
> > 
> > \pset n_decimals 2
> > SELECT 1::numeric;
> > 
> > produces:
> > 
> > =================================================================
> > ==3574709==ERROR: AddressSanitizer: heap-buffer-overflow....
> > WRITE of size 1 at 0x502000008732 thread T0
> >      #0 0x48621f in format_ndecimals 
> > /home/postgres/postgresql/postgres/src/fe_utils/print.c:444
> >      #1 0x4977cb in printQuery 
> > /home/postgres/postgresql/postgres/src/fe_utils/print.c:3907
> > 
> > on an ASAN enabled build.
> > 
> > Here, only two bytes are allocated for "1". I think the code needs to check 
> > the
> > available fractional digits and compute the required output size before 
> > copying.
> > 
> 
> I think I fixed it. Not sure because I don't have an ASAN enabled build. I
> have no idea how to get that.

One option is to build that way:

CC="gcc" meson setup meson_build -Dprefix=${PGINSTROOT} -Dpgport=${PGPORT} 
-Db_sanitize=address -Dbuildtype=debug

and then "export ASAN_OPTIONS="halt_on_error=false:abort_on_error=false"".

The same can be done with autoconf too and something like "-O0 -ggdb3 
-fsanitize=address".

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to