summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2023-03-01 16:30:17 +0000
committerTom Lane2023-03-01 16:30:17 +0000
commitb1a9d8ef254fab59c35a504490e14b2d9e1bbb92 (patch)
tree6c34c913980d4db2f29bd9187b40565113ae5b4c /src/test
parent73e779b3807dedb9b0bc20d4ce12a350033aa646 (diff)
Avoid fetching one past the end of translate()'s "to" parameter.
This is usually harmless, but if you were very unlucky it could provoke a segfault due to the "to" string being right up against the end of memory. Found via valgrind testing (so we might've found it earlier, except that our regression tests lacked any exercise of translate()'s deletion feature). Fix by switching the order of the test-for-end-of-string and advance-pointer steps. While here, compute "to_ptr + tolen" just once. (Smarter compilers might figure that out for themselves, but let's just make sure.) Report and fix by Daniil Anisimov, in bug #17816. Discussion: https://postgr.es/m/17816-70f3d2764e88a108@postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/strings.out6
-rw-r--r--src/test/regress/sql/strings.sql1
2 files changed, 7 insertions, 0 deletions
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index 6fbaf152cd1..213b236a145 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -1771,6 +1771,12 @@ SELECT translate('12345', '14', 'ax');
a23x5
(1 row)
+SELECT translate('12345', '134', 'a');
+ translate
+-----------
+ a25
+(1 row)
+
SELECT ascii('x');
ascii
-------
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index 8eb6bf30af5..7cb31859e4b 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -608,6 +608,7 @@ SELECT ltrim('zzzytrim', 'xyz');
SELECT translate('', '14', 'ax');
SELECT translate('12345', '14', 'ax');
+SELECT translate('12345', '134', 'a');
SELECT ascii('x');
SELECT ascii('');