git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86ab28f)
Fix uninitialized memory reference.
Fri, 1 Dec 2017 15:01:50 +0000 (10:01 -0500)
Fri, 1 Dec 2017 15:05:00 +0000 (10:05 -0500)
Without this, when partdesc->nparts == 0, we end up calling
ExecBuildSlotPartitionKeyDescription without initializing values
and isnull.

Reported by Coverity via Michael Paquier. Patch by Michael Paquier,
reviewed and revised by Amit Langote.

Discussion: http://postgr.es/m/CAB7nPqQ3mwkdMoPY-ocgTpPnjd8TKOadMxdTtMLvEzF8480Zfg@mail.gmail.com


diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index 59a0ca4597c2f4631750c9bd54015c8820c10639..34875945e81412eca0b74c15b68c4715c638481c 100644 (file)
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -206,13 +206,6 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
slot = myslot;
}
- /* Quick exit */
- if (partdesc->nparts == 0)
- {
- result = -1;
- break;
- }
-
/*
* Extract partition key from tuple. Expression evaluation machinery
* that FormPartitionKeyDatum() invokes expects ecxt_scantuple to
@@ -223,6 +216,17 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
*/
ecxt->ecxt_scantuple = slot;
FormPartitionKeyDatum(parent, slot, estate, values, isnull);
+
+ /*
+ * Nothing for get_partition_for_tuple() to do if there are no
+ * partitions to begin with.
+ */
+ if (partdesc->nparts == 0)
+ {
+ result = -1;
+ break;
+ }
+
cur_index = get_partition_for_tuple(rel, values, isnull);
/*
diff --git a/src/test/regress/expected/insert.out b/src/test/regress/expected/insert.out
index b7b37dbc39961757f1448aacf2d27529cd3cd9d0..dcbaad8e2fd1ec98b2b0fec0aca37074d6fa46aa 100644 (file)
--- a/src/test/regress/expected/insert.out
+++ b/src/test/regress/expected/insert.out
@@ -165,6 +165,10 @@ create table range_parted (
a text,
b int
) partition by range (a, (b+0));
+-- no partitions, so fail
+insert into range_parted values ('a', 11);
+ERROR: no partition of relation "range_parted" found for row
+DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, 11).
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);
diff --git a/src/test/regress/sql/insert.sql b/src/test/regress/sql/insert.sql
index 310b818076c491043b62a94e30727cbafe25e35b..0150b6bb0febb8d0de3ad04bb26971013b50a9f7 100644 (file)
--- a/src/test/regress/sql/insert.sql
+++ b/src/test/regress/sql/insert.sql
@@ -90,6 +90,10 @@ create table range_parted (
a text,
b int
) partition by range (a, (b+0));
+
+-- no partitions, so fail
+insert into range_parted values ('a', 11);
+
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /