Re: Avoid possible dereference null pointer (contrib/postgres_fdw/postgres_fdw.c)

Fujii Masao <masao.fujii@oss.nttdata.com>

From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Ranier Vilela <ranier.vf@gmail.com>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2025-06-17T05:38:11Z
Lists: pgsql-hackers

On 2025/06/17 4:48, Ranier Vilela wrote:
> Hi.
> 
> In the function *estimate_path_cost_size* the parameter
> fpextra can be NULL.

Yes.


> It is necessary to always check its validity,
> as is already done in other parts of the source.
> 
> patch attached.

  				adjust_foreign_grouping_path_cost(root, pathkeys,
  												  retrieved_rows, width,
-												  fpextra->limit_tuples,
+												  fpextra ? fpextra->limit_tuples : 0.0,
  												  &disabled_nodes,
  												  &startup_cost, &run_cost);

I couldn't find a query that would reach this code path with
fpextra == NULL, but I agree the current code is fragile.
So I think it's a good idea to add the check before accessing
the field.

Regards,

-- 
Fujii Masao
NTT DATA Japan Corporation




Commits

  1. postgres_fdw: Add Assert to estimate_path_cost_size().