| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Guillaume Lelarge <guillaume(dot)lelarge(at)dalibo(dot)com> |
| Cc: | Nathan Bossart <nathandbossart(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Setting the number of digits after the decimal point with a psql's pset variable |
| Date: | 2026-11-03 06:05:09 |
| Message-ID: | aul5lWD6L9CdIz+r@bdtpg |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sivirilova Marija | 2026-11-03 06:07:31 | RE: [***DKIM violation***] Re: [PATCH] Fix heap-buffer-overflow in PGTYPEStimestamp_defmt_scan() |
| Previous Message | Henson Choi | 2026-11-03 05:57:08 | Re: [PATCH v1] Fix for bug #19773 : pg_dump differing generation expressions of inherited columns |