aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-02-28 18:49:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-02-28 18:49:53 +0000
commit6c8f478623d2b6ba608eccc13a93ac7c25556b48 (patch)
tree225d6d0e57c6697849f783c9aa523a2b71056b22
parent109177fe3a5f3609b9adae98ead7517156305ef1 (diff)
downloadpostgresql-6c8f478623d2b6ba608eccc13a93ac7c25556b48.tar.gz
postgresql-6c8f478623d2b6ba608eccc13a93ac7c25556b48.zip
Fix buffer allocations in encoding conversion routines so that they won't
fail on zero-length inputs. This isn't an issue in normal use because the conversion infrastructure skips calling the converters for empty strings. However a problem was created by yesterday's patch to check whether the right conversion function is supplied in CREATE CONVERSION. The most future-proof fix seems to be to make the converters safe for this corner case.
-rw-r--r--src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c26
-rw-r--r--src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c6
-rw-r--r--src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c6
4 files changed, 20 insertions, 22 deletions
diff --git a/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c b/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c
index 8b8e8b04e27..147b9c12b95 100644
--- a/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c
+++ b/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.16.2.2 2009/01/29 19:23:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.16.2.3 2009/02/28 18:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -203,7 +203,7 @@ koi8r_to_win1251(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN1251);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
koi8r2mic(src, buf, len);
mic2win1251(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -221,7 +221,7 @@ win1251_to_koi8r(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_KOI8R);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win12512mic(src, buf, len);
mic2koi8r(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -239,7 +239,7 @@ koi8r_to_win866(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN866);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
koi8r2mic(src, buf, len);
mic2win866(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -257,7 +257,7 @@ win866_to_koi8r(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_KOI8R);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win8662mic(src, buf, len);
mic2koi8r(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -281,7 +281,7 @@ win866_to_win1251(PG_FUNCTION_ARGS)
* not in KOI8R. As we use MULE_INTERNAL/KOI8R as an intermediary, we
* will fail to convert those characters.
*/
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win8662mic(src, buf, len);
mic2win1251(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -300,7 +300,7 @@ win1251_to_win866(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_WIN866);
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win12512mic(src, buf, len);
mic2win866(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -318,7 +318,7 @@ iso_to_koi8r(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_KOI8R);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
iso2mic(src, buf, len);
mic2koi8r(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -336,7 +336,7 @@ koi8r_to_iso(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ISO_8859_5);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
koi8r2mic(src, buf, len);
mic2iso(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -355,7 +355,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
iso2mic(src, buf, len);
mic2win1251(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -374,7 +374,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win12512mic(src, buf, len);
mic2iso(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -393,7 +393,7 @@ iso_to_win866(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN866);
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
iso2mic(src, buf, len);
mic2win866(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -412,7 +412,7 @@ win866_to_iso(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_ISO_8859_5);
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win8662mic(src, buf, len);
mic2iso(buf, dest, strlen((char *) buf));
pfree(buf);
diff --git a/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c b/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c
index d6422620e85..64ec861a372 100644
--- a/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c
+++ b/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.19.2.1 2009/01/29 19:23:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.19.2.2 2009/02/28 18:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,8 +27,6 @@
*/
#include "sjis.map"
-#define ENCODING_GROWTH_RATE 4
-
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(euc_jp_to_sjis);
diff --git a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
index 58cb12043e4..082bdc7882b 100644
--- a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
+++ b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.18.2.1 2009/01/29 19:23:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.18.2.2 2009/02/28 18:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -59,7 +59,7 @@ euc_tw_to_big5(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_BIG5);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
euc_tw2mic(src, buf, len);
mic2big5(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -77,7 +77,7 @@ big5_to_euc_tw(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_EUC_TW);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
big52mic(src, buf, len);
mic2euc_tw(buf, dest, strlen((char *) buf));
pfree(buf);
diff --git a/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c b/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c
index 68c33164508..0637a23db77 100644
--- a/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c
+++ b/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.15.2.1 2009/01/29 19:23:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.15.2.2 2009/02/28 18:49:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -115,7 +115,7 @@ latin2_to_win1250(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
latin22mic(src, buf, len);
mic2win1250(buf, dest, strlen((char *) buf));
pfree(buf);
@@ -133,7 +133,7 @@ win1250_to_latin2(PG_FUNCTION_ARGS)
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2);
- buf = palloc(len * ENCODING_GROWTH_RATE);
+ buf = palloc(len * ENCODING_GROWTH_RATE + 1);
win12502mic(src, buf, len);
mic2latin2(buf, dest, strlen((char *) buf));
pfree(buf);