Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ef65d0

Browse files
committed
Avoid dereferencing an undefined pointer in DecodeInterval().
Commite39f990 moved some code up closer to the start ofDecodeInterval(), without noticing that it had been implicitlyrelying on previous checks to reject the case of empty input.Given empty input, we'd now dereference a pointer that hadn't beenset, possibly leading to a core dump. (But if we fail to provokea SIGSEGV, nothing bad happens, and the expected syntax error isthrown a bit later.)Per bug #17788 from Alexander Lakhin. Back-patch to v15 wherethe fault was introduced.Discussion:https://postgr.es/m/17788-dabac9f98f7eafd5@postgresql.org
1 parentecb01e6 commit0ef65d0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
33653365
* to dump in postgres style, not SQL style.)
33663366
*----------
33673367
*/
3368-
if (IntervalStyle==INTSTYLE_SQL_STANDARD&&*field[0]=='-')
3368+
if (IntervalStyle==INTSTYLE_SQL_STANDARD&&nf>0&&*field[0]=='-')
33693369
{
33703370
force_negative= true;
33713371
/* Check for additional explicit signs */

‎src/test/regress/expected/interval.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,11 @@ SELECT interval '-23 hours 45 min 12.34 sec',
857857
-23:45:12.34 | -1 23:45:12.34 | -1-2 -1 -23:45:12.34 | -0-10 +1 +23:45:12.34
858858
(1 row)
859859

860+
-- edge case for sign-matching rules
861+
SELECT interval ''; -- error
862+
ERROR: invalid input syntax for type interval: ""
863+
LINE 1: SELECT interval '';
864+
^
860865
-- test outputting iso8601 intervals
861866
SET IntervalStyle to iso_8601;
862867
select interval '0' AS "zero",

‎src/test/regress/sql/interval.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ SELECT interval '-23 hours 45 min 12.34 sec',
277277
interval'-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
278278
interval'-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
279279

280+
-- edge case for sign-matching rules
281+
SELECT interval'';-- error
282+
280283
-- test outputting iso8601 intervals
281284
SET IntervalStyle to iso_8601;
282285
select interval'0'AS"zero",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp