pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix several one-byte buffer over-reads in to_number
8+ messages / 3 participants
[nested] [flat]
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
2016-08-08 20:16 ` Re: pgsql: Fix several one-byte buffer over-reads in to_number Piotr Stefaniak <postgres@piotr-stefaniak.me>
0 siblings, 1 reply; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/9a46324fd46506c86b190d3163902ed90072c53c
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix several one-byte buffer over-reads in to_number
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
@ 2016-08-08 20:16 ` Piotr Stefaniak <postgres@piotr-stefaniak.me>
2016-08-09 15:04 ` Re: pgsql: Fix several one-byte buffer over-reads in to_number Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Piotr Stefaniak @ 2016-08-08 20:16 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; pgsql-committers
On 2016-08-08 17:18, Peter Eisentraut wrote:
> Fix several one-byte buffer over-reads in to_number
I've been meaning to update my patch like this, but didn't want to
bother you before trying to find more issues with formatting.c (still
haven't found the time for that, sadly):
@@ -4188,13 +4188,10 @@ NUM_numpart_from_char(NUMProc *Np, int id, int
input_len)
(id == NUM_0 || id == NUM_9) ? "NUM_0/9" : id ==
NUM_DEC ? "NUM_DEC" : "???");
#endif
- if (*Np->inout_p == ' ')
- Np->inout_p++;
-
#define OVERLOAD_TEST (Np->inout_p >= Np->inout + input_len)
#define AMOUNT_TEST(_s) (input_len-(Np->inout_p-Np->inout) >= _s)
- if (*Np->inout_p == ' ')
+ while (!OVERLOAD_TEST && isspace((unsigned char) *Np->inout_p))
Np->inout_p++;
if (OVERLOAD_TEST)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix several one-byte buffer over-reads in to_number
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 20:16 ` Re: pgsql: Fix several one-byte buffer over-reads in to_number Piotr Stefaniak <postgres@piotr-stefaniak.me>
@ 2016-08-09 15:04 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2016-08-09 15:04 UTC (permalink / raw)
To: Piotr Stefaniak <postgres@piotr-stefaniak.me>; +Cc: Peter Eisentraut <peter_e@gmx.net>; pgsql-committers
Piotr Stefaniak <postgres@piotr-stefaniak.me> writes:
> I've been meaning to update my patch like this, but didn't want to
> bother you before trying to find more issues with formatting.c (still
> haven't found the time for that, sadly):
> - if (*Np->inout_p == ' ')
> + while (!OVERLOAD_TEST && isspace((unsigned char) *Np->inout_p))
> Np->inout_p++;
Meh. I agree that replacing the "== ' '" test with isspace() would be
an improvement, since that seems to be the way it's done elsewhere in
formatting.c. But changing this into a loop, so that it's willing to
consume any amount of whitespace, is a nontrivial change in the
specification of to_number(). I'm not at all sure it's a good idea;
IMO the point of to_number() is to parse numbers according to a fairly
tightly controlled format.
I'd even argue that unconditionally consuming a single space is the wrong
thing here. Rather, I think what this is meant to be doing is treating a
space as one of the possible alternatives for a sign character, and so
instead of this what the code ought to be is an alternative on the same
footing as '+' or '-', a few lines down:
else if (*Np->inout_p == '+')
{
*Np->number = '+'; /* set + */
Np->inout_p++;
}
+ else if (isspace((unsigned char) *Np->inout_p))
+ {
+ *Np->number = '+'; /* set + */
+ Np->inout_p++;
+ }
}
}
regards, tom lane
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
REL9_5_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/04cee8f835bcf95ff80b734c335927aaf6551d2d
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
REL9_4_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/20f870fd7cab8446c208a4a9cfa5ec2a441ef69c
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
REL9_3_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/43d7a0af5340b32161bbc89cdb886f4211fa1496
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
REL9_2_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/b0134fe84da073f5c8ed4bbfac4a7111c1f7d799
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix several one-byte buffer over-reads in to_number
@ 2016-08-08 15:18 Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 8+ messages in thread
From: Peter Eisentraut @ 2016-08-08 15:18 UTC (permalink / raw)
To: pgsql-committers
Fix several one-byte buffer over-reads in to_number
Several places in NUM_numpart_from_char(), which is called from the SQL
function to_number(text, text), could accidentally read one byte past
the end of the input buffer (which comes from the input text datum and
is not null-terminated).
1. One leading space character would be skipped, but there was no check
that the input was at least one byte long. This does not happen in
practice, but for defensiveness, add a check anyway.
2. Commit 4a3a1e2cf apparently accidentally doubled that code that skips
one space character (so that two spaces might be skipped), but there
was no overflow check before skipping the second byte. Fix by
removing that duplicate code.
3. A logic error would allow a one-byte over-read when looking for a
trailing sign (S) placeholder.
In each case, the extra byte cannot be read out directly, but looking at
it might cause a crash.
The third item was discovered by Piotr Stefaniak, the first two were
found and analyzed by Tom Lane and Peter Eisentraut.
Branch
------
REL9_1_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/d555d26429568e1a95f75c1a751933ebb63b82c6
Modified Files
--------------
src/backend/utils/adt/formatting.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2016-08-09 15:04 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 20:16 ` Piotr Stefaniak <postgres@piotr-stefaniak.me>
2016-08-09 15:04 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
2016-08-08 15:18 pgsql: Fix several one-byte buffer over-reads in to_number Peter Eisentraut <peter_e@gmx.net>
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