Commit 1ca717f3 authored by Tom Lane's avatar Tom Lane

plpython security and error handling fixes, from

Kevin Jacobs and Brad McLean.
parent b0df7a60
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)
This diff is collapsed.
......@@ -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();
......@@ -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';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment