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
a401226b
Commit
a401226b
authored
Mar 18, 2010
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent the injection of invalidly encoded strings by PL/Python into PostgreSQL
with a few strategically placed pg_verifymbstr calls.
parent
ab5694e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
doc/src/sgml/plpython.sgml
doc/src/sgml/plpython.sgml
+12
-1
src/pl/plpython/plpython.c
src/pl/plpython/plpython.c
+5
-1
No files found.
doc/src/sgml/plpython.sgml
View file @
a401226b
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.4
5 2010/03/13 20:55:05
petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.4
6 2010/03/18 19:43:03
petere Exp $ -->
<chapter id="plpython">
<title>PL/Python - Python Procedural Language</title>
...
...
@@ -340,6 +340,17 @@ $$ LANGUAGE plpythonu;
builtin <literal>str</literal>, and the result is passed to the
input function of the PostgreSQL data type.
</para>
<para>
Strings in Python 2 are required to be in the PostgreSQL server
encoding when they are passed to PostgreSQL. Strings that are
not valid in the current server encoding will raise an error,
but not all encoding mismatches can be detected, so garbage
data can still result when this is not done correctly. Unicode
strings are converted to the correct encoding automatically, so
it can be safer and more convenient to use those. In Python 3,
all strings are Unicode strings.
</para>
</listitem>
<listitem>
...
...
src/pl/plpython/plpython.c
View file @
a401226b
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.14
0 2010/03/18 13:23:56
petere Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.14
1 2010/03/18 19:43:03
petere Exp $
*
*********************************************************************
*/
...
...
@@ -2174,6 +2174,7 @@ PLyObject_ToDatum(PLyTypeInfo *info,
errmsg
(
"could not convert Python object into cstring: Python string representation appears to contain null bytes"
)));
else
if
(
slen
>
plen
)
elog
(
ERROR
,
"could not convert Python object into cstring: Python string longer than reported length"
);
pg_verifymbstr
(
plrv_sc
,
slen
,
false
);
rv
=
InputFunctionCall
(
&
arg
->
typfunc
,
plrv_sc
,
arg
->
typioparam
,
-
1
);
}
PG_CATCH
();
...
...
@@ -2871,6 +2872,7 @@ PLy_spi_prepare(PyObject *self, PyObject *args)
}
}
pg_verifymbstr
(
query
,
strlen
(
query
),
false
);
plan
->
plan
=
SPI_prepare
(
query
,
plan
->
nargs
,
plan
->
types
);
if
(
plan
->
plan
==
NULL
)
elog
(
ERROR
,
"SPI_prepare failed: %s"
,
...
...
@@ -3078,6 +3080,7 @@ PLy_spi_execute_query(char *query, long limit)
oldcontext
=
CurrentMemoryContext
;
PG_TRY
();
{
pg_verifymbstr
(
query
,
strlen
(
query
),
false
);
rv
=
SPI_execute
(
query
,
PLy_curr_procedure
->
fn_readonly
,
limit
);
}
PG_CATCH
();
...
...
@@ -3353,6 +3356,7 @@ PLy_output(volatile int level, PyObject *self, PyObject *args)
oldcontext
=
CurrentMemoryContext
;
PG_TRY
();
{
pg_verifymbstr
(
sv
,
strlen
(
sv
),
false
);
elog
(
level
,
"%s"
,
sv
);
}
PG_CATCH
();
...
...
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