[NBTREE] Possible NULL pointer dereference (backend/access/nbtree/nbutils.c) - Mailing list pgsql-hackers

From Ranier Vilela
Subject [NBTREE] Possible NULL pointer dereference (backend/access/nbtree/nbutils.c)
Date
Msg-id CAEudQApXsNo0pvk_Kt+k8TpFcOtPiiumAnEt3nE1u=ubOf8TjQ@mail.gmail.com
Whole thread Raw
Responses Re: [NBTREE] Possible NULL pointer dereference (backend/access/nbtree/nbutils.c)
Re: [NBTREE] Possible NULL pointer dereference (backend/access/nbtree/nbutils.c)
List pgsql-hackers
Hi,

Is possible that BTreeTupleSetNAtts, leave everything tidy, so that BTreeTupleGetHeapTID doesn't fail.
BTreeTupleGetHeapTID can return NULL.

But, as we can see:
1. Line 2085 (nbtutils.c):
    if (BTreeTupleGetHeapTID(itup) != NULL && tupnatts != nkeyatts)
2. Line 803 (nbtsearch.c):
    if (heapTid == NULL)

Maybe, better make sure, because:
3. Line 2285 (nbtutils.c):
    ItemPointerCopy(BTreeTupleGetMaxHeapTID(lastleft), pivotheaptid);
4. Line 2316 (nbtutils.c) :
    ItemPointerCopy(BTreeTupleGetHeapTID(firstright), pivotheaptid);

Can dereference NULL pointer (pivotheaptid) at runtime (release version).

itemptr.h:
#define ItemPointerCopy(fromPointer, toPointer) \
( \
AssertMacro(PointerIsValid(toPointer)), \
AssertMacro(PointerIsValid(fromPointer)), \
*(toPointer) = *(fromPointer) \
)

regards,
Ranier Vilela

pgsql-hackers by date:

Previous
From: Jesse Zhang
Date:
Subject: Re: Fix for configure error in 9.5/9.6 on macOS 11.0 Big Sur
Next
From: Ranier Vilela
Date:
Subject: Re: [NBTREE] Possible NULL pointer dereference (backend/access/nbtree/nbutils.c)