summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2023-03-14 23:17:31 +0000
committerTom Lane2023-03-14 23:17:31 +0000
commit8e33fb9ef1df7f1a1e7ef2fe0dbddfff2520f161 (patch)
treecb65aa443854bdde26898c6775db6d393fcdb426 /src/test
parent234941a3bbf32266e9e2d3d9bc7648aec850d8c4 (diff)
Fix corner case bug in numeric to_char() some more.
The band-aid applied in commit f0bedf3e4 turns out to still need some work: it made sure we didn't set Np->last_relevant too small (to the left of the decimal point), but it didn't prevent setting it too large (off the end of the partially-converted string). This could result in fetching data beyond the end of the allocated space, which with very bad luck could cause a SIGSEGV, though I don't see any hazard of interesting memory disclosure. Per bug #17839 from Thiago Nunes. The bug's pretty ancient, so back-patch to all supported versions. Discussion: https://postgr.es/m/17839-aada50db24d7b0da@postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/numeric.out6
-rw-r--r--src/test/regress/sql/numeric.sql1
2 files changed, 7 insertions, 0 deletions
diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out
index ced7980709f..6400bcb5254 100644
--- a/src/test/regress/expected/numeric.out
+++ b/src/test/regress/expected/numeric.out
@@ -1266,6 +1266,12 @@ SELECT '' AS to_char_26, to_char('100'::numeric, 'FM999');
| 100
(1 row)
+SELECT to_char('12345678901'::float8, 'FM9999999999D9999900000000000000000');
+ to_char
+-----------------
+ ##########.####
+(1 row)
+
-- Check parsing of literal text in a format string
SELECT '' AS to_char_27, to_char('100'::numeric, 'foo999');
to_char_27 | to_char
diff --git a/src/test/regress/sql/numeric.sql b/src/test/regress/sql/numeric.sql
index e5ff2b59029..9924419a577 100644
--- a/src/test/regress/sql/numeric.sql
+++ b/src/test/regress/sql/numeric.sql
@@ -799,6 +799,7 @@ SELECT '' AS to_char_23, to_char(val, '9.999EEEE') FROM num_data;
SELECT '' AS to_char_24, to_char('100'::numeric, 'FM999.9');
SELECT '' AS to_char_25, to_char('100'::numeric, 'FM999.');
SELECT '' AS to_char_26, to_char('100'::numeric, 'FM999');
+SELECT to_char('12345678901'::float8, 'FM9999999999D9999900000000000000000');
-- Check parsing of literal text in a format string
SELECT '' AS to_char_27, to_char('100'::numeric, 'foo999');