summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-01-29 19:23:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-01-29 19:23:42 +0000
commit0d65eea3dac92b1a1bd5e39134958a1213d13d14 (patch)
tree7ad231c8c0d852ac6ea5cc6a6be157c4f8851b1b /src/include
parentb5b3134813a089ee84d0b068c1781ebfb2a63ec6 (diff)
Replace argument-checking Asserts with regular test-and-elog checks in all
encoding conversion functions. These are not can't-happen cases because it's possible to create a conversion with the wrong conversion function for the specified encoding pair. That would lead to an Assert crash in an Assert-enabled build, or incorrect conversion otherwise, neither of which is desirable. This would be a DOS issue if production databases were customarily built with asserts enabled, but fortunately that's not so. Per an observation by Heikki. Back-patch to all supported branches.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/mb/pg_wchar.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h
index dc89af9d507..65c99a2797f 100644
--- a/src/include/mb/pg_wchar.h
+++ b/src/include/mb/pg_wchar.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.82 2009/01/04 18:37:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.83 2009/01/29 19:23:42 tgl Exp $
*
* NOTES
* This is used both by the backend and by libpq, but should not be
@@ -325,6 +325,19 @@ typedef struct
uint32 utf2; /* UTF-8 code 2 */
} pg_local_to_utf_combined;
+/*
+ * Support macro for encoding conversion functions to validate their
+ * arguments. (This could be made more compact if we included fmgr.h
+ * here, but we don't want to do that because this header file is also
+ * used by frontends.)
+ */
+#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
+ check_encoding_conversion_args(PG_GETARG_INT32(0), \
+ PG_GETARG_INT32(1), \
+ PG_GETARG_INT32(4), \
+ (srcencoding), \
+ (destencoding))
+
/*
* These functions are considered part of libpq's exported API and
@@ -408,6 +421,12 @@ extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
extern int pg_verify_mbstr_len(int encoding, const char *mbstr, int len,
bool noError);
+extern void check_encoding_conversion_args(int src_encoding,
+ int dest_encoding,
+ int len,
+ int expected_src_encoding,
+ int expected_dest_encoding);
+
extern void report_invalid_encoding(int encoding, const char *mbstr, int len);
extern void report_untranslatable_char(int src_encoding, int dest_encoding,
const char *mbstr, int len);