Skip to content

Commit 0f08df4

Browse files
Avoid treating nonrequired nbtree keys as required.
Consistently prevent nbtree array advancement from treating a scankey as required when operating in pstate.forcenonrequired mode. Otherwise, we risk a NULL pointer dereference. This was possible in the path where _bt_check_compare is called to recheck a tuple that advanced all of the scan's arrays to matching values: its continuescan=false handling expects _bt_advance_array_keys to have been called with a valid pstate, but it'll always be NULL during sktrig_required=false calls (which is how _bt_advance_array_keys must be called when pstate.forcenonrequired). Oversight in commit 8a51027, which optimized nbtree search scan key comparisons. Author: Peter Geoghegan <pg@bowt.ie> Reported-By: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://postgr.es/m/CAHgHdKsn2W=gPBmj7p6MjQFvxB+zZDBkwTSg0o3f5Hh8rkRrsA@mail.gmail.com Discussion: https://postgr.es/m/CAH2-WzmodSE+gpTd1CRGU9ez8ytyyDS+Kns2r9NzgUp1s56kpw@mail.gmail.com
1 parent 1681a70 commit 0f08df4

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ _bt_advance_array_keys(IndexScanDesc scan, BTReadPageState *pstate,
18261826

18271827
/* Recheck _bt_check_compare on behalf of caller */
18281828
if (_bt_check_compare(scan, dir, tuple, tupnatts, tupdesc, false,
1829-
false, &continuescan,
1829+
!sktrig_required, &continuescan,
18301830
&nsktrig) &&
18311831
!so->scanBehind)
18321832
{
@@ -2799,8 +2799,6 @@ _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
27992799
{
28002800
BTScanOpaque so = (BTScanOpaque) scan->opaque;
28012801

2802-
Assert(!forcenonrequired || advancenonrequired);
2803-
28042802
*continuescan = true; /* default assumption */
28052803

28062804
for (; *ikey < so->numberOfKeys; (*ikey)++)

0 commit comments

Comments
 (0)