pgsql: Robustify find_base_rel and find_base_rel_ignore_join

Поиск
Список
Период
Сортировка
От David Rowley
Тема pgsql: Robustify find_base_rel and find_base_rel_ignore_join
Дата
Msg-id E1qm4eb-006ZDY-QP@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Robustify find_base_rel and find_base_rel_ignore_join

Improve find_base_rel() and find_base_rel_ignore_join() so that they
raise an ERROR if they ever receive a negative relid value in
non-cassert builds.  If either of these functions had ever received a
negative relid then they'd have attempted to access memory that does not
belong to simple_rel_array.

Because no evidence has been presented of actual cases where bugs have
caused this to happen, here we take a lightweight approach to checking
for negative values and simply cast both values to uint32 before
performing the comparison.  This will cause any negative relids to be
seen as greater than simple_rel_array_size which will ERROR rather than
attempt to access a negative simple_rel_array element.  Obviously, the
run-time error is better than a crash, so it makes sense to protect
against this, especially when it can be done without adding any
additional run-time overhead.

There is a slight change here if the functions are ever called with a
relid of 0.  This will pass the bounds check, but that array entry
should be NULL (along with the corresponding simple_rte_array entry), so
won't pass the "if (rel)" condition and still fall through and raise an
ERROR.

Author: Ranier Vilela
Reviewed-by: Ashutosh Bapat, David Rowley
Discussion: https://postgr.es/m/CAEudQArQSghBu2gLojg4o_tnHj_x2HcS%3D%2BwewL3NJS8z0VnK%2Bg%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d40d8272190ce5f1641b9afb83a3752101af6a38

Modified Files
--------------
src/backend/optimizer/util/relnode.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: doc: Fix descriptions related to the handling of non-ASCII chara
Следующее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: Revert "pg_resetwal: Improve error with wrong/missing data direc