pgsql: Further harden PL/Perl against tied-scalar mischief.

Поиск
Список
Период
Сортировка
Искать

pgsql: Further harden PL/Perl against tied-scalar mischief.

От:
Noah Misch <noah@leadboat.com>
Дата:
Further harden PL/Perl against tied-scalar mischief.

PL/Perl decides whether Perl threw an error by testing SvTRUE(ERRSV).
If the thrown value is an object whose class overloads "bool", that
runs user-supplied Perl code.  There is no eval{} in scope at some of
these tests, so if that code throws in turn, Perl writes the message
to stderr and exits the backend, not the behavior we want.

To fix, don't ask Perl at all in the case that matters.  Any reference
is true regardless of what its class claims, so a thrown object is an
error by definition, while overloading cannot apply to a non-reference.
Add errsv_is_true() to encapsulate that and replace tests of ERRSV
with that.

Also, consider the possibility that trying to stringify ERRSV throws
an error, which can also be arranged with a hostile object definition.
That risks an infinite loop in PG_PERL_TRY, so install code to prevent
repeating such a loop.

Lastly, stringify ERRSV outside our ereport() calls not inside.  If we
do it inside then a thrown Perl error temporarily leaks an errordata[]
slot for the unfinished ereport.  While it's not clear that this makes
it possible to overrun ERRORDATA_STACK_SIZE, it seems best to avoid
the leak.

Reported-by: Dwij Mehta 
Author: Andrew Dunstan 
Co-authored-by: Tom Lane 
Backpatch-through: 14
Security: CVE-2026-116326

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/41a3a980ee30b37127edce6b68dd9791bf0e7b4b
Author: Andrew Dunstan 

Modified Files
--------------
src/pl/plperl/plperl.c | 81 +++++++++++++++++++++++++++++++++++++-------------
src/pl/plperl/plperl.h | 65 +++++++++++++++++++++++++++++++++-------
2 files changed, 116 insertions(+), 30 deletions(-)

FAQ