</listitem>
</varlistentry>
+ <varlistentry id="guc-backslash-quote" xreflabel="backslash_quote">
+ <term><varname>BACKSLASH_QUOTE</varname> (<type>string</type>)</term>
+ <indexterm><primary>strings</><secondary>backslash quotes</></>
+ <indexterm>
+ <primary><varname>backslash_quote</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ This controls whether a quote mark can be represented by
+ <literal>\'</> in a string literal. The preferred, SQL-standard way
+ to represent a quote mark is by doubling it (<literal>''</>) but
+ <productname>PostgreSQL</> has historically also accepted
+ <literal>\'</>. However, use of <literal>\'</> creates security risks
+ because in some client character set encodings, there are multibyte
+ characters in which the last byte is numerically equivalent to ASCII
+ <literal>\</>. If client-side code does escaping incorrectly then a
+ SQL-injection attack is possible. This risk can be prevented by
+ making the server reject queries in which a quote mark appears to be
+ escaped by a backslash.
+ The allowed values of <varname>backslash_quote</> are
+ <literal>on</> (allow <literal>\'</> always),
+ <literal>off</> (reject always), and
+ <literal>safe_encoding</> (allow only if client encoding does not
+ allow ASCII <literal>\</> within a multibyte character).
+ <literal>safe_encoding</> is the default setting.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><varname>CLIENT_ENCODING</varname> (<type>string</type>)</term>
<indexterm><primary>character set encoding</></>
static int xcdepth = 0; /* depth of nesting in slash-star comments */
+/*
+ * GUC variables. This is a DIRECT violation of the warning given at the
+ * head of gram.y, ie flex/bison code must not depend on any GUC variables;
+ * as such, changing their values can induce very unintuitive behavior.
+ * But we shall have to live with it as a short-term thing until the switch
+ * to SQL-standard string syntax is complete.
+ */
+BackslashQuoteType backslash_quote = BACKSLASH_QUOTE_SAFE_ENCODING;
+
/*
* literalbuf is used to accumulate literal values when multiple rules
* are needed to parse a single literal. Call startlit to reset buffer
addlit(yytext, yyleng);
}
<xq>{xqescape} {
+ if (yytext[1] == '\'')
+ {
+ if (backslash_quote == BACKSLASH_QUOTE_OFF ||
+ (backslash_quote == BACKSLASH_QUOTE_SAFE_ENCODING &&
+ PG_ENCODING_IS_CLIENT_ONLY(pg_get_client_encoding())))
+ elog(ERROR, "unsafe use of \\' in a string literal");
+ }
addlitchar(unescape_single_char(yytext[1]));
}
<xq>{xqoctesc} {
#include "optimizer/geqo.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
+#include "parser/gramparse.h"
#include "parser/parse_expr.h"
#include "storage/fd.h"
#include "storage/freespace.h"
static const char *assign_msglvl(int *var, const char *newval,
bool doit, bool interactive);
+static const char *assign_backslash_quote(const char *newval, bool doit,
+ bool interactive);
/*
* Debugging options
* and is kept in sync by assign_hooks.
*/
static double phony_random_seed;
+static char *backslash_quote_string;
static char *client_encoding_string;
static char *datestyle_string;
static char *default_iso_level_string;
static struct config_string
ConfigureNamesString[] =
{
+ {
+ {"backslash_quote", PGC_USERSET}, &backslash_quote_string,
+ "safe_encoding", assign_backslash_quote, NULL
+ },
+
{
{"client_encoding", PGC_USERSET, GUC_IS_NAME}, &client_encoding_string,
"SQL_ASCII", assign_client_encoding, NULL
return newval; /* OK */
}
+static const char *
+assign_backslash_quote(const char *newval, bool doit, bool interactive)
+{
+ BackslashQuoteType bq;
+ bool bqbool;
+
+ /*
+ * Although only "on", "off", and "safe_encoding" are documented,
+ * we use parse_bool so we can accept all the likely variants of
+ * "on" and "off".
+ */
+ if (strcasecmp(newval, "safe_encoding") == 0)
+ bq = BACKSLASH_QUOTE_SAFE_ENCODING;
+ else if (parse_bool(newval, &bqbool))
+ {
+ bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
+ }
+ else
+ return NULL; /* reject */
+
+ if (doit)
+ backslash_quote = bq;
+
+ return newval;
+}
+
#include "guc-file.c"
#transform_null_equals = false
#statement_timeout = 0 # 0 is disabled, in milliseconds
#db_user_namespace = false
-
+#backslash_quote = safe_encoding # on, off, or safe_encoding
+
"cpu_operator_cost",
"geqo_selection_bias",
+ "backslash_quote",
"default_transaction_isolation",
"search_path",
"statement_timeout",
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h"
+typedef enum
+{
+ BACKSLASH_QUOTE_OFF,
+ BACKSLASH_QUOTE_ON,
+ BACKSLASH_QUOTE_SAFE_ENCODING
+} BackslashQuoteType;
+
+/* GUC variables in scan.l (every one of these is a bad idea :-() */
+extern BackslashQuoteType backslash_quote;
+
+
/* from parser.c */
extern void parser_param_set(Oid *typev, int nargs);
extern Oid param_type(int t);