Re: [REPORT] Static analys warnings

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [REPORT] Static analys warnings
Date: 2020-05-04 22:49:57
Message-ID: CAEudQAokNwc_FB821yQDx4TmXgWEFXpbgh5fPWqBkt=yH3Zd=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fix possible overflow when converting, possible negative number to uint16.

postingoff can be -1,when converts to uint16, overflow can raise.
Otherwise, truncation can be occurs, losing precision, from int (31 bits)
to uint16 (15 bits)
There is a little confusion in the parameters of some functions in this
file, postigoff is declared as int, other declared as uint16.

src/backend/access/nbtree/nbtinsert.c
static void _bt_insertonpg(Relation rel, BTScanInsert itup_key,
Buffer buf,
Buffer cbuf,
BTStack stack,
IndexTuple itup,
Size itemsz,
OffsetNumber newitemoff,
int postingoff, // INT
bool split_only_page);
static Buffer _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf,
Buffer cbuf, OffsetNumber newitemoff, Size newitemsz,
IndexTuple newitem, IndexTuple orignewitem,
IndexTuple nposting, uint16 postingoff); // UINT16

regards,
Ranier Vilela

Attachment Content-Type Size
fix_possible_overflow_postingoff.patch application/octet-stream 808 bytes

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-05-05 01:52:29 Another modest proposal for docs formatting: catalog descriptions
Previous Message Andrew Dunstan 2020-05-04 22:44:14 Re: do {} while (0) nitpick