Lists: | pgsql-hackers |
---|
From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | pset_quoted_string is broken |
Date: | 2014-10-26 22:40:24 |
Message-ID: | CAApHDvrvbkpn6BVWCnDEfE2v+kgRmNgcpmL3rF7d-+-PnwMTcg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
It seems the buffer created in pset_quoted_string is just 1 char too small.
This breaks psql's \pset for me, though I've no idea why the buildfarm is
not complaining a bit more.
As it stands, if the function is given an empty string to quote, it tries
to build a string with 2 single quotes and a NUL. This needs 3 chars, not 2.
The attached simple patch fixes the problem.
Attachment | Content-Type | Size |
---|---|---|
pset_quoted_string_fix.diff | text/plain | 389 bytes |
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | David Rowley <dgrowleyml(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: pset_quoted_string is broken |
Date: | 2014-10-26 23:20:14 |
Message-ID: | 15760.1414365614@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> It seems the buffer created in pset_quoted_string is just 1 char too small.
Yeah, that's a bug. Fix pushed, thanks!
> This breaks psql's \pset for me, though I've no idea why the buildfarm is
> not complaining a bit more.
I think in most cases, maxalign padding of the malloc allocation would
result in there being room for another byte without trashing anything
important. You must be using a libc that notices and complains about
even 1-byte buffer overruns.
regards, tom lane
From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: pset_quoted_string is broken |
Date: | 2014-10-27 01:28:49 |
Message-ID: | CAApHDvrjCULr1NH75BK6qso70K8vQeooo0r3RTv7eqSD2iz_pA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, Oct 27, 2014 at 12:20 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > It seems the buffer created in pset_quoted_string is just 1 char too
> small.
>
> Yeah, that's a bug. Fix pushed, thanks!
>
>
Thanks for committing.
> > This breaks psql's \pset for me, though I've no idea why the buildfarm is
> > not complaining a bit more.
>
> I think in most cases, maxalign padding of the malloc allocation would
> result in there being room for another byte without trashing anything
> important. You must be using a libc that notices and complains about
> even 1-byte buffer overruns.
>
>
>
I'm using MSVC.
After a bit of reading it seems like when compiled in debug mode that
malloc() uses something called _malloc_dbg() which allocates a bit more
memory to allow for more strict checking of buffer overruns.
http://msdn.microsoft.com/en-us/library/974tc9t1.aspx
I guess all the MSVC buildfarm members must be compiled in release mode
then? I wonder if it would be worth changing one to build with debug as it
seem like none of the buildfarm animals picked this up despite there being
a regression test to ensure \pset works.
Regards
David Rowley