pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix contrib/seg to be more wary of long input numbers.
Date: Wed, 21 Dec 2022 22:52:06 +0000
Message-ID: <E1p87wT-004mo9-DM@gemulon.postgresql.org> (raw)

Fix contrib/seg to be more wary of long input numbers.

seg stores the number of significant digits in an input number
in a "char" field.  If char is signed, and the input is more than
127 digits long, the count can read out as negative causing
seg_out() to print garbage (or, if you're really unlucky,
even crash).

To fix, clamp the digit count to be not more than FLT_DIG.
(In theory this loses some information about what the original
input was, but it doesn't seem like useful information; it would
not survive dump/restore in any case.)

Also, in case there are stored values of the seg type containing
bad data, add a clamp in seg_out's restore() subroutine.

Per bug #17725 from Robins Tharakan.  It's been like this
forever, so back-patch to all supported branches.

Discussion: https://postgr.es/m/17725-0a09313b67fbe86e@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/701c881f782b93ee29587112390bd3bfe035e78d

Modified Files
--------------
contrib/seg/expected/seg.out |  7 +++++++
contrib/seg/seg.c            |  8 ++++++--
contrib/seg/segparse.y       | 22 +++++++++++++++++-----
contrib/seg/sql/seg.sql      |  3 +++
4 files changed, 33 insertions(+), 7 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1p87wT-004mo9-DM@gemulon.postgresql.org>
Permalink:  ../E1p87wT-004mo9-DM@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1p87wT-004mo9-DM@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix contrib/seg to be more wary of long input numbers.
  In-Reply-To: <E1p87wT-004mo9-DM@gemulon.postgresql.org>
  References: <E1p87wT-004mo9-DM@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox