mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-30 19:00:29 +08:00
Add tests for json{b}_populate_recordset() crash case.
The problem reported as CVE-2017-15098 was already resolved in HEAD by
commit 37a795a60
, but let's add the relevant test cases anyway.
Michael Paquier and Tom Lane, per a report from David Rowley.
Security: CVE-2017-15098
This commit is contained in:
parent
dfc015dcf4
commit
b574228715
@ -1857,6 +1857,19 @@ SELECT json_populate_recordset(row(1,2)::j_ordered_pair, '[{"x": 0}, {"y": 3}]')
|
||||
|
||||
SELECT json_populate_recordset(row(1,2)::j_ordered_pair, '[{"x": 1, "y": 0}]');
|
||||
ERROR: value for domain j_ordered_pair violates check constraint "j_ordered_pair_check"
|
||||
-- negative cases where the wrong record type is supplied
|
||||
select * from json_populate_recordset(row(0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned row contains 1 attribute, but query expects 2.
|
||||
select * from json_populate_recordset(row(0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned type integer at ordinal position 1, but query expects text.
|
||||
select * from json_populate_recordset(row(0::int,0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned row contains 3 attributes, but query expects 2.
|
||||
select * from json_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned type integer at ordinal position 1, but query expects text.
|
||||
-- test type info caching in json_populate_record()
|
||||
CREATE TEMP TABLE jspoptest (js json);
|
||||
INSERT INTO jspoptest
|
||||
|
@ -2539,6 +2539,19 @@ SELECT jsonb_populate_recordset(row(1,2)::jb_ordered_pair, '[{"x": 0}, {"y": 3}]
|
||||
|
||||
SELECT jsonb_populate_recordset(row(1,2)::jb_ordered_pair, '[{"x": 1, "y": 0}]');
|
||||
ERROR: value for domain jb_ordered_pair violates check constraint "jb_ordered_pair_check"
|
||||
-- negative cases where the wrong record type is supplied
|
||||
select * from jsonb_populate_recordset(row(0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned row contains 1 attribute, but query expects 2.
|
||||
select * from jsonb_populate_recordset(row(0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned type integer at ordinal position 1, but query expects text.
|
||||
select * from jsonb_populate_recordset(row(0::int,0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned row contains 3 attributes, but query expects 2.
|
||||
select * from jsonb_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
ERROR: function return row and query-specified return row do not match
|
||||
DETAIL: Returned type integer at ordinal position 1, but query expects text.
|
||||
-- jsonb_to_record and jsonb_to_recordset
|
||||
select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}')
|
||||
as x(a int, b text, d text);
|
||||
|
@ -553,6 +553,12 @@ SELECT json_populate_recordset(null::j_ordered_pair, '[{"x": 0, "y": 1}]');
|
||||
SELECT json_populate_recordset(row(1,2)::j_ordered_pair, '[{"x": 0}, {"y": 3}]');
|
||||
SELECT json_populate_recordset(row(1,2)::j_ordered_pair, '[{"x": 1, "y": 0}]');
|
||||
|
||||
-- negative cases where the wrong record type is supplied
|
||||
select * from json_populate_recordset(row(0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from json_populate_recordset(row(0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from json_populate_recordset(row(0::int,0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from json_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
|
||||
-- test type info caching in json_populate_record()
|
||||
CREATE TEMP TABLE jspoptest (js json);
|
||||
|
||||
|
@ -669,6 +669,12 @@ SELECT jsonb_populate_recordset(null::jb_ordered_pair, '[{"x": 0, "y": 1}]');
|
||||
SELECT jsonb_populate_recordset(row(1,2)::jb_ordered_pair, '[{"x": 0}, {"y": 3}]');
|
||||
SELECT jsonb_populate_recordset(row(1,2)::jb_ordered_pair, '[{"x": 1, "y": 0}]');
|
||||
|
||||
-- negative cases where the wrong record type is supplied
|
||||
select * from jsonb_populate_recordset(row(0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from jsonb_populate_recordset(row(0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from jsonb_populate_recordset(row(0::int,0::int,0::int),'[{"a":"1","b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
select * from jsonb_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text);
|
||||
|
||||
-- jsonb_to_record and jsonb_to_recordset
|
||||
|
||||
select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}')
|
||||
|
Loading…
Reference in New Issue
Block a user