mirror of
https://github.com/postgres/postgres.git
synced 2025-05-17 06:41:24 +03:00
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.
This commit is contained in:
parent
17485e504d
commit
5156266ab6
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.6.4.3 2009/01/29 19:25:12 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.6.4.4 2009/02/28 18:50:24 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -201,7 +201,7 @@ koi8r_to_win1251(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN1251);
|
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);
|
koi8r2mic(src, buf, len);
|
||||||
mic2win1251(buf, dest, strlen(buf));
|
mic2win1251(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -219,7 +219,7 @@ win1251_to_koi8r(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_KOI8R);
|
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);
|
win12512mic(src, buf, len);
|
||||||
mic2koi8r(buf, dest, strlen(buf));
|
mic2koi8r(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -237,7 +237,7 @@ koi8r_to_alt(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ALT);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ALT);
|
||||||
|
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
koi8r2mic(src, buf, len);
|
koi8r2mic(src, buf, len);
|
||||||
mic2alt(buf, dest, strlen(buf));
|
mic2alt(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -255,7 +255,7 @@ alt_to_koi8r(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_KOI8R);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_KOI8R);
|
||||||
|
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
alt2mic(src, buf, len);
|
alt2mic(src, buf, len);
|
||||||
mic2koi8r(buf, dest, strlen(buf));
|
mic2koi8r(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -279,7 +279,7 @@ alt_to_win1251(PG_FUNCTION_ARGS)
|
|||||||
* not in KOI8R. As we use MULE_INTERNAL/KOI8R as an intermediary, we
|
* not in KOI8R. As we use MULE_INTERNAL/KOI8R as an intermediary, we
|
||||||
* will fail to convert those characters.
|
* will fail to convert those characters.
|
||||||
*/
|
*/
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
alt2mic(src, buf, len);
|
alt2mic(src, buf, len);
|
||||||
mic2win1251(buf, dest, strlen(buf));
|
mic2win1251(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -298,7 +298,7 @@ win1251_to_alt(PG_FUNCTION_ARGS)
|
|||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ALT);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ALT);
|
||||||
|
|
||||||
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
win12512mic(src, buf, len);
|
win12512mic(src, buf, len);
|
||||||
mic2alt(buf, dest, strlen(buf));
|
mic2alt(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -316,7 +316,7 @@ iso_to_koi8r(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_KOI8R);
|
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);
|
iso2mic(src, buf, len);
|
||||||
mic2koi8r(buf, dest, strlen(buf));
|
mic2koi8r(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -334,7 +334,7 @@ koi8r_to_iso(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ISO_8859_5);
|
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);
|
koi8r2mic(src, buf, len);
|
||||||
mic2iso(buf, dest, strlen(buf));
|
mic2iso(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -353,7 +353,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
|
|||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
|
||||||
|
|
||||||
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
iso2mic(src, buf, len);
|
iso2mic(src, buf, len);
|
||||||
mic2win1251(buf, dest, strlen(buf));
|
mic2win1251(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -372,7 +372,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
|
|||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
|
||||||
|
|
||||||
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
win12512mic(src, buf, len);
|
win12512mic(src, buf, len);
|
||||||
mic2iso(buf, dest, strlen(buf));
|
mic2iso(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -391,7 +391,7 @@ iso_to_alt(PG_FUNCTION_ARGS)
|
|||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_ALT);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_ALT);
|
||||||
|
|
||||||
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
iso2mic(src, buf, len);
|
iso2mic(src, buf, len);
|
||||||
mic2alt(buf, dest, strlen(buf));
|
mic2alt(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -410,7 +410,7 @@ alt_to_iso(PG_FUNCTION_ARGS)
|
|||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_ISO_8859_5);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_ISO_8859_5);
|
||||||
|
|
||||||
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
alt2mic(src, buf, len);
|
alt2mic(src, buf, len);
|
||||||
mic2iso(buf, dest, strlen(buf));
|
mic2iso(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.6.4.4 2009/01/29 19:25:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.6.4.5 2009/02/28 18:50:24 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -69,7 +69,7 @@ euc_jp_to_sjis(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_SJIS);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_SJIS);
|
||||||
|
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
euc_jp2mic(src, buf, len);
|
euc_jp2mic(src, buf, len);
|
||||||
mic2sjis(buf, dest, strlen(buf));
|
mic2sjis(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -87,7 +87,7 @@ sjis_to_euc_jp(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_EUC_JP);
|
CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_EUC_JP);
|
||||||
|
|
||||||
buf = palloc(len * ENCODING_GROWTH_RATE);
|
buf = palloc(len * ENCODING_GROWTH_RATE + 1);
|
||||||
sjis2mic(src, buf, len);
|
sjis2mic(src, buf, len);
|
||||||
mic2euc_jp(buf, dest, strlen(buf));
|
mic2euc_jp(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.6.4.3 2009/02/28 18:50:24 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -57,7 +57,7 @@ euc_tw_to_big5(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_BIG5);
|
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);
|
euc_tw2mic(src, buf, len);
|
||||||
mic2big5(buf, dest, strlen(buf));
|
mic2big5(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -75,7 +75,7 @@ big5_to_euc_tw(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_EUC_TW);
|
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);
|
big52mic(src, buf, len);
|
||||||
mic2euc_tw(buf, dest, strlen(buf));
|
mic2euc_tw(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.6.4.3 2009/02/28 18:50:25 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -113,7 +113,7 @@ latin2_to_win1250(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250);
|
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);
|
latin22mic(src, buf, len);
|
||||||
mic2win1250(buf, dest, strlen(buf));
|
mic2win1250(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
@ -131,7 +131,7 @@ win1250_to_latin2(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2);
|
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);
|
win12502mic(src, buf, len);
|
||||||
mic2latin2(buf, dest, strlen(buf));
|
mic2latin2(buf, dest, strlen(buf));
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user