diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2018-04-13 16:43:33 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2018-04-13 16:43:33 -0400 |
commit | 7c44c46deb495a2f3861f402d7f2109263e3d50a (patch) | |
tree | 2de4f5483b2366a69050fffbd0a9e5bacf29c15c | |
parent | 8bf358c18ec930ddfb998873369e2fc38608d3e1 (diff) | |
download | postgresql-7c44c46deb495a2f3861f402d7f2109263e3d50a.tar.gz postgresql-7c44c46deb495a2f3861f402d7f2109263e3d50a.zip |
Prevent segfault in expand_tuple with no missing values
Commit 16828d5c forgot to check that it had a set of missing values
before trying to retrieve a value from it.
An additional query to add coverage for this code is added to the
regression test.
Per bug report from Andreas Seltenreich.
-rw-r--r-- | src/backend/access/common/heaptuple.c | 2 | ||||
-rw-r--r-- | src/test/regress/expected/fast_default.out | 35 | ||||
-rw-r--r-- | src/test/regress/sql/fast_default.sql | 14 |
3 files changed, 50 insertions, 1 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index c64645675e6..b9802b92c0b 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -981,7 +981,7 @@ expand_tuple(HeapTuple *targetHeapTuple, Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum); - if (attrmiss[attnum].ammissingPresent) + if (attrmiss && attrmiss[attnum].ammissingPresent) { fill_val(attr, nullBits ? &nullBits : NULL, diff --git a/src/test/regress/expected/fast_default.out b/src/test/regress/expected/fast_default.out index 3568fa7b8a9..ef8d04f59c8 100644 --- a/src/test/regress/expected/fast_default.out +++ b/src/test/regress/expected/fast_default.out @@ -505,6 +505,41 @@ SELECT comp(); Unchanged (1 row) +-- query to exercise expand_tuple function +CREATE TABLE t1 AS +SELECT 1::int AS a , 2::int AS b +FROM generate_series(1,20) q; +ALTER TABLE t1 ADD COLUMN c text; +SELECT a, + stddev(cast((SELECT sum(1) FROM generate_series(1,20) x) AS float4)) + OVER (PARTITION BY a,b,c ORDER BY b) + AS z +FROM t1; + a | z +---+--- + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 + 1 | 0 +(20 rows) + +DROP TABLE t1; DROP TABLE T; DROP FUNCTION set(name); DROP FUNCTION comp(); diff --git a/src/test/regress/sql/fast_default.sql b/src/test/regress/sql/fast_default.sql index ea707d402af..0e660330f77 100644 --- a/src/test/regress/sql/fast_default.sql +++ b/src/test/regress/sql/fast_default.sql @@ -347,6 +347,20 @@ SELECT c_text FROM T WHERE c_int = -1; SELECT comp(); +-- query to exercise expand_tuple function +CREATE TABLE t1 AS +SELECT 1::int AS a , 2::int AS b +FROM generate_series(1,20) q; + +ALTER TABLE t1 ADD COLUMN c text; + +SELECT a, + stddev(cast((SELECT sum(1) FROM generate_series(1,20) x) AS float4)) + OVER (PARTITION BY a,b,c ORDER BY b) + AS z +FROM t1; + +DROP TABLE t1; DROP TABLE T; DROP FUNCTION set(name); DROP FUNCTION comp(); |