pgsql: Fix various overflow hazards in date and timestamp functions. - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: Fix various overflow hazards in date and timestamp functions.
Date
Msg-id E1tKjjv-001ur3-C4@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix various overflow hazards in date and timestamp functions.

This commit makes use of the overflow-aware routines in int.h to
fix a variety of reported overflow bugs in the date and timestamp
code.  It seems unlikely that this fixes all such bugs in this
area, but since the problems seem limited to cases that are far
beyond any realistic usage, I'm not going to worry too much.  Note
that for one bug, I've chosen to simply add a comment about the
overflow hazard because fixing it would require quite a bit of code
restructuring that doesn't seem worth the risk.

Since this is a bug fix, it could be back-patched, but given the
risk of conflicts with the new routines in int.h and the overall
risk/reward ratio of this patch, I've opted not to do so for now.

Fixes bug #18585 (except for the one case that's just commented).

Reported-by: Alexander Lakhin
Author: Matthew Kim, Nathan Bossart
Reviewed-by: Joseph Koshakow, Jian He
Discussion: https://postgr.es/m/31ad2cd1-db94-bdb3-f91a-65ffdb4bef95%40gmail.com
Discussion: https://postgr.es/m/18585-db646741dd649abd%40postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0a27c3d0f733c132a4c5122e749a619d02937a8a

Modified Files
--------------
src/backend/utils/adt/date.c           |   9 ++-
src/backend/utils/adt/formatting.c     | 100 ++++++++++++++++++++++++++++++---
src/backend/utils/adt/timestamp.c      |   4 ++
src/include/common/int.h               |  48 ++++++++++++++++
src/test/regress/expected/date.out     |   2 +
src/test/regress/expected/horology.out |  16 ++++++
src/test/regress/sql/date.sql          |   1 +
src/test/regress/sql/horology.sql      |   8 +++
8 files changed, 179 insertions(+), 9 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Simplify executor's determination of whether to use parallelism.
Next
From: Daniel Gustafsson
Date:
Subject: pgsql: Fix small memory leaks in GUC checks