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
1ca717f3
Commit
1ca717f3
authored
Nov 16, 2001
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plpython security and error handling fixes, from
Kevin Jacobs and Brad McLean.
parent
b0df7a60
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
272 additions
and
57 deletions
+272
-57
src/pl/plpython/error.expected
src/pl/plpython/error.expected
+26
-9
src/pl/plpython/plpython.c
src/pl/plpython/plpython.c
+200
-47
src/pl/plpython/plpython_error.sql
src/pl/plpython/plpython_error.sql
+8
-0
src/pl/plpython/plpython_function.sql
src/pl/plpython/plpython_function.sql
+38
-1
No files found.
src/pl/plpython/error.expected
View file @
1ca717f3
SELECT invalid_type_uncaught('rick');
ERROR: plpython: Call of function `__plpython_procedure_invalid_type_uncaught_1175341' failed.
NOTICE: plpython: in function __plpython_procedure_invalid_type_uncaught_49801:
plpy.SPIError: Cache lookup for type `test' failed.
SELECT invalid_type_caught('rick');
NOTICE: ("Cache lookup for type `test' failed.",)
invalid_type_caught
---------------------
(1 row)
NOTICE: plpython: in function __plpython_procedure_invalid_type_caught_49802:
plpy.SPIError: Cache lookup for type `test' failed.
SELECT invalid_type_reraised('rick');
ERROR: plpython: Call of function `__plpython_procedure_invalid_type_reraised_1175343' failed.
plpy.
Error: ("Cache lookup for type `test' failed.",)
NOTICE: plpython: in function __plpython_procedure_invalid_type_reraised_49803:
plpy.
SPIError: Cache lookup for type `test' failed.
SELECT valid_type('rick');
valid_type
------------
(1 row)
SELECT read_file('/etc/passwd');
ERROR: plpython: Call of function `__plpython_procedure_read_file_49809' failed.
exceptions.IOError: can't open files in restricted mode
SELECT write_file('/tmp/plpython','This is very bad');
ERROR: plpython: Call of function `__plpython_procedure_write_file_49810' failed.
exceptions.IOError: can't open files in restricted mode
SELECT getpid();
ERROR: plpython: Call of function `__plpython_procedure_getpid_49811' failed.
exceptions.AttributeError: getpid
SELECT uname();
ERROR: plpython: Call of function `__plpython_procedure_uname_49812' failed.
exceptions.AttributeError: uname
SELECT sys_exit();
ERROR: plpython: Call of function `__plpython_procedure_sys_exit_49813' failed.
exceptions.AttributeError: exit
SELECT sys_argv();
sys_argv
----------------
['RESTRICTED']
(1 row)
src/pl/plpython/plpython.c
View file @
1ca717f3
This diff is collapsed.
Click to expand it.
src/pl/plpython/plpython_error.sql
View file @
1ca717f3
...
...
@@ -7,3 +7,11 @@ SELECT invalid_type_uncaught('rick');
SELECT
invalid_type_caught
(
'rick'
);
SELECT
invalid_type_reraised
(
'rick'
);
SELECT
valid_type
(
'rick'
);
-- Security sandbox tests
SELECT
read_file
(
'/etc/passwd'
);
SELECT
write_file
(
'/tmp/plpython'
,
'This is very bad'
);
SELECT
getpid
();
SELECT
uname
();
SELECT
sys_exit
();
SELECT
sys_argv
();
src/pl/plpython/plpython_function.sql
View file @
1ca717f3
...
...
@@ -257,6 +257,12 @@ if len(rv):
return None
'
LANGUAGE
'plpython'
;
/* Flat out syntax error
*/
CREATE
FUNCTION
sql_syntax_error
()
RETURNS
text
AS
'plpy.execute("syntax error")'
LANGUAGE
'plpython'
;
/* check the handling of uncaught python exceptions
*/
...
...
@@ -287,5 +293,36 @@ return seq
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
read_file
(
text
)
RETURNS
text
AS
'
return open(args[0]).read()
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
write_file
(
text
,
text
)
RETURNS
text
AS
'
open(args[0],"w").write(args[1])
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
getpid
()
RETURNS
int4
AS
'
import os
return os.getpid()
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
uname
()
RETURNS
int4
AS
'
import os
return os.uname()
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
sys_exit
()
RETURNS
text
AS
'
import sys
return sys.exit()
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
sys_argv
()
RETURNS
text
AS
'
import sys
return str(sys.argv)
'
LANGUAGE
'plpython'
;
CREATE
OR
REPLACE
FUNCTION
sys_version
()
RETURNS
text
AS
'
import sys
return str(sys.version)
'
LANGUAGE
'plpython'
;
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