postgres.git / summary / log / commit / refs

commit    4efef9d18e637f5d1e9e09129785d73f5f8619b4
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Thu Jun 18 16:22:55 2026 +0000
First released in: 14.24, 15.19, 16.15, 17.11, 18.6

    hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop.
    
    Add CHECK_FOR_INTERRUPTS() to the while loop in plperl_to_hstore()
    that dereferences chains of Perl references, so that a circular
    reference (e.g. $x = \$x) can be cancelled by the user instead of
    spinning indefinitely.  (We looked at detecting such circular
    references, but it seems more trouble than it's worth.)
    
    This is a follow-up to da82fbb8f, which fixed the same issue in
    SV_to_JsonbValue() in jsonb_plperl.
    
    Author: Aleksander Alekseev <aleksander@tigerdata.com>
    Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/CAJ7c6TPbjkzUk4qJ5dHvDNEz0hBuFue3A-XWz_=897z+BC+z8A@mail.gmail.com
    Backpatch-through: 14


contrib/hstore_plperl/hstore_plperl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c index 945b90eba64..b5f72138f17 100644 --- a/contrib/hstore_plperl/hstore_plperl.c +++ b/contrib/hstore_plperl/hstore_plperl.c @@ -2,6 +2,7 @@ #include "fmgr.h" #include "hstore/hstore.h" +#include "miscadmin.h" #include "plperl.h" PG_MODULE_MAGIC; @@ -107,7 +108,15 @@ plperl_to_hstore(PG_FUNCTION_ARGS) /* Dereference references recursively. */ while (SvROK(in)) + { + /* + * It's possible for circular references to make this an infinite + * loop. Checking for such a situation seems like much more trouble + * than it's worth, but let's provide a way to break out of the loop. + */ + CHECK_FOR_INTERRUPTS(); in = SvRV(in); + } /* Now we must have a hash. */ if (SvTYPE(in) != SVt_PVHV) [parent: 1fec5ddfdc2d]