Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
40bc4c26
Commit
40bc4c26
authored
May 05, 2009
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable the use of Unicode escapes in string constants (U&'') when
standard_conforming_strings is not on, for security reasons.
parent
616bceb8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
2 deletions
+76
-2
doc/src/sgml/syntax.sgml
doc/src/sgml/syntax.sgml
+12
-1
src/backend/parser/scan.l
src/backend/parser/scan.l
+6
-1
src/test/regress/expected/strings.out
src/test/regress/expected/strings.out
+39
-0
src/test/regress/sql/strings.sql
src/test/regress/sql/strings.sql
+19
-0
No files found.
doc/src/sgml/syntax.sgml
View file @
40bc4c26
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.13
1 2009/04/27 16:27:36 momjian
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.13
2 2009/05/05 18:32:17 petere
Exp $ -->
<chapter id="sql-syntax">
<chapter id="sql-syntax">
<title>SQL Syntax</title>
<title>SQL Syntax</title>
...
@@ -499,6 +499,17 @@ U&'d!0061t!+000061' UESCAPE '!'
...
@@ -499,6 +499,17 @@ U&'d!0061t!+000061' UESCAPE '!'
specified.
specified.
</para>
</para>
<para>
Also, the Unicode escape syntax for string constants only works
when the configuration
parameter <xref linkend="guc-standard-conforming-strings"> is
turned on. This is because otherwise this syntax could confuse
clients that parse the SQL statements to the point that it could
lead to SQL injections and similar security issues. If the
parameter is set to off, this syntax will be rejected with an
error message.
</para>
<para>
<para>
To include the escape character in the string literally, write it
To include the escape character in the string literally, write it
twice.
twice.
...
...
src/backend/parser/scan.l
View file @
40bc4c26
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.15
1 2009/04/19 21:08:54 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.15
2 2009/05/05 18:32:17 petere
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -469,6 +469,11 @@ other .
...
@@ -469,6 +469,11 @@ other .
startlit();
startlit();
}
}
{xusstart} {
{xusstart} {
if (!standard_conforming_strings)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsafe use of string constant with Unicode escapes"),
errdetail("String constants with Unicode escapes cannot be used when standard_conforming_strings is off.")));
SET_YYLLOC();
SET_YYLLOC();
BEGIN(xus);
BEGIN(xus);
startlit();
startlit();
...
...
src/test/regress/expected/strings.out
View file @
40bc4c26
...
@@ -22,6 +22,7 @@ ERROR: syntax error at or near "' - third line'"
...
@@ -22,6 +22,7 @@ ERROR: syntax error at or near "' - third line'"
LINE 3: ' - third line'
LINE 3: ' - third line'
^
^
-- Unicode escapes
-- Unicode escapes
SET standard_conforming_strings TO on;
SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
data
data
------
------
...
@@ -34,6 +35,18 @@ SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
...
@@ -34,6 +35,18 @@ SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
dat\+000061
dat\+000061
(1 row)
(1 row)
SELECT U&' \' UESCAPE '!' AS "tricky";
tricky
--------
\
(1 row)
SELECT 'tricky' AS U&"\" UESCAPE '!';
\
--------
tricky
(1 row)
SELECT U&'wrong: \061';
SELECT U&'wrong: \061';
ERROR: invalid Unicode escape value at or near "\061'"
ERROR: invalid Unicode escape value at or near "\061'"
LINE 1: SELECT U&'wrong: \061';
LINE 1: SELECT U&'wrong: \061';
...
@@ -46,6 +59,32 @@ SELECT U&'wrong: +0061' UESCAPE '+';
...
@@ -46,6 +59,32 @@ SELECT U&'wrong: +0061' UESCAPE '+';
ERROR: invalid Unicode escape character at or near "+'"
ERROR: invalid Unicode escape character at or near "+'"
LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
^
^
SET standard_conforming_strings TO off;
SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
SELECT U&' \' UESCAPE '!' AS "tricky";
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
SELECT 'tricky' AS U&"\" UESCAPE '!';
\
--------
tricky
(1 row)
SELECT U&'wrong: \061';
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
SELECT U&'wrong: \+0061';
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
SELECT U&'wrong: +0061' UESCAPE '+';
ERROR: unsafe use of string constant with Unicode escapes
DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
RESET standard_conforming_strings;
--
--
-- test conversions between various string types
-- test conversions between various string types
-- E021-10 implicit casting among the character data types
-- E021-10 implicit casting among the character data types
...
...
src/test/regress/sql/strings.sql
View file @
40bc4c26
...
@@ -17,13 +17,32 @@ SELECT 'first line'
...
@@ -17,13 +17,32 @@ SELECT 'first line'
AS
"Illegal comment within continuation"
;
AS
"Illegal comment within continuation"
;
-- Unicode escapes
-- Unicode escapes
SET
standard_conforming_strings
TO
on
;
SELECT
U
&
'd
\0
061t
\+
000061'
AS
U
&
"d
\0
061t
\+
000061"
;
SELECT
U
&
'd!0061t
\+
000061'
UESCAPE
'!'
AS
U
&
"d*0061t
\+
000061"
UESCAPE
'*'
;
SELECT
U
&
'
\'
UESCAPE '
!
' AS "tricky";
SELECT '
tricky
' AS U&"
\"
UESCAPE '
!
';
SELECT U&'
wrong
:
\
061
';
SELECT U&'
wrong
:
\
+
0061
';
SELECT U&'
wrong
:
+
0061
' UESCAPE '
+
';
SET standard_conforming_strings TO off;
SELECT U&'
d
\
0061
t
\
+
000061
' AS U&"d
\0
061t
\+
000061";
SELECT U&'
d
\
0061
t
\
+
000061
' AS U&"d
\0
061t
\+
000061";
SELECT U&'
d
!
0061
t
\
+
000061
' UESCAPE '
!
' AS U&"d*0061t
\+
000061" UESCAPE '
*
';
SELECT U&'
d
!
0061
t
\
+
000061
' UESCAPE '
!
' AS U&"d*0061t
\+
000061" UESCAPE '
*
';
SELECT U&'
\
' UESCAPE '
!
' AS "tricky";
SELECT '
tricky
' AS U&"
\"
UESCAPE '
!
';
SELECT U&'
wrong
:
\
061
';
SELECT U&'
wrong
:
\
061
';
SELECT U&'
wrong
:
\
+
0061
';
SELECT U&'
wrong
:
\
+
0061
';
SELECT U&'
wrong
:
+
0061
' UESCAPE '
+
';
SELECT U&'
wrong
:
+
0061
' UESCAPE '
+
';
RESET standard_conforming_strings;
--
--
-- test conversions between various string types
-- test conversions between various string types
-- E021-10 implicit casting among the character data types
-- E021-10 implicit casting among the character data types
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment