Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd40d827

Browse files
committed
Robustify find_base_rel and find_base_rel_ignore_join
Improve find_base_rel() and find_base_rel_ignore_join() so that theyraise an ERROR if they ever receive a negative relid value innon-cassert builds. If either of these functions had ever received anegative relid then they'd have attempted to access memory that does notbelong to simple_rel_array.Because no evidence has been presented of actual cases where bugs havecaused this to happen, here we take a lightweight approach to checkingfor negative values and simply cast both values to uint32 beforeperforming the comparison. This will cause any negative relids to beseen as greater than simple_rel_array_size which will ERROR rather thanattempt to access a negative simple_rel_array element. Obviously, therun-time error is better than a crash, so it makes sense to protectagainst this, especially when it can be done without adding anyadditional run-time overhead.There is a slight change here if the functions are ever called with arelid of 0. This will pass the bounds check, but that array entryshould be NULL (along with the corresponding simple_rte_array entry), sowon't pass the "if (rel)" condition and still fall through and raise anERROR.Author: Ranier VilelaReviewed-by: Ashutosh Bapat, David RowleyDiscussion:https://postgr.es/m/CAEudQArQSghBu2gLojg4o_tnHj_x2HcS%3D%2BwewL3NJS8z0VnK%2Bg%40mail.gmail.com
1 parent3ef18a9 commitd40d827

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

‎src/backend/optimizer/util/relnode.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,8 @@ find_base_rel(PlannerInfo *root, int relid)
406406
{
407407
RelOptInfo*rel;
408408

409-
Assert(relid>0);
410-
411-
if (relid<root->simple_rel_array_size)
409+
/* use an unsigned comparison to prevent negative array element access */
410+
if ((uint32)relid< (uint32)root->simple_rel_array_size)
412411
{
413412
rel=root->simple_rel_array[relid];
414413
if (rel)
@@ -432,9 +431,8 @@ find_base_rel(PlannerInfo *root, int relid)
432431
RelOptInfo*
433432
find_base_rel_ignore_join(PlannerInfo*root,intrelid)
434433
{
435-
Assert(relid>0);
436-
437-
if (relid<root->simple_rel_array_size)
434+
/* use an unsigned comparison to prevent negative array element access */
435+
if ((uint32)relid< (uint32)root->simple_rel_array_size)
438436
{
439437
RelOptInfo*rel;
440438
RangeTblEntry*rte;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp