mongo_fdw icon indicating copy to clipboard operation
mongo_fdw copied to clipboard

Server crash when using query parameter

Open pludov opened this issue 2 years ago • 1 comments

I get consistent server crash when running a query from plpgsql with an inequality condition that refers to a variable. The crash happens exactly on the 6th execution of the request...

It does not occur if I change the inequality to an equality, or if I use a constant rather than a variable.

Versions:

  • postgres: 13.2
  • Mongo FDW: 5.4.0
  • Mongo: 4.2.18

Reproduction script:

CREATE FOREIGN TABLE test ( importeddate text )
    SERVER whatever
    OPTIONS (database 'test', collection 'test');

-- perform a query from with inequality and variable
create or replace procedure gogogo() as $$
declare val text;
begin
        val := 'ZZZ';
        perform from test where importeddate > val  ;
end
$$ LANGUAGE plpgsql;

-- Now do 6 call...
call crash(); call crash(); call crash(); call crash(); call crash(); call crash();

pludov avatar Jun 03 '22 10:06 pludov

Thanks, @pludov for reporting an issue.

This issue is reproducible at my end as well. This is a bug and this is due to missed handling of Param node in case of comparison operator while preparing query filter.

You can apply attached patch to fix this issue.

We will try to commit these changes as soon as possible. Fix-crash-v1.txt

vaibhavdalvi93 avatar Jun 03 '22 11:06 vaibhavdalvi93