pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Assignment before assert
4+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2025-02-14 67a0234157 9fcd360498 d6894d6a08 22240b2818 cb19cd956f 971566e965  Fix assertion on dereferenced object
* Assignment before assert
@ 2025-02-13 17:08  Dmitry Koval <d.koval@postgrespro.ru>
  0 siblings, 1 reply; 4+ messages in thread

From: Dmitry Koval @ 2025-02-13 17:08 UTC (permalink / raw)
  To: pgsql-hackers

Hi!
Function EvalPlanQualFetchRowMark contains an assignment

	ExecRowMark *erm = earm->rowmark;

before assert

	Assert(earm != NULL);

Maybe these lines need to be swapped?

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com

Attachments:

v1-0001-fix-assignment-before-assert.patch (text/plain, 661B) download diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 39d80ccfbad..963aa390620 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -2662,13 +2662,15 @@ bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot) { ExecAuxRowMark *earm = epqstate->relsubs_rowmark[rti - 1]; - ExecRowMark *erm = earm->rowmark; + ExecRowMark *erm; Datum datum; bool isNull; Assert(earm != NULL); Assert(epqstate->origslot != NULL); + erm = earm->rowmark; + if (RowMarkRequiresRowShareLock(erm->markType)) elog(ERROR, "EvalPlanQual doesn't support locking rowmarks");
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Assignment before assert
@ 2025-02-13 23:15  Daniel Gustafsson <daniel@yesql.se>
  parent: Dmitry Koval <d.koval@postgrespro.ru>
  0 siblings, 1 reply; 4+ messages in thread

From: Daniel Gustafsson @ 2025-02-13 23:15 UTC (permalink / raw)
  To: Dmitry Koval <d.koval@postgrespro.ru>; +Cc: pgsql-hackers

> On 13 Feb 2025, at 18:08, Dmitry Koval <d.koval@postgrespro.ru> wrote:
> 
> Hi!
> Function EvalPlanQualFetchRowMark contains an assignment
> 
> ExecRowMark *erm = earm->rowmark;
> 
> before assert
> 
> Assert(earm != NULL);
> 
> Maybe these lines need to be swapped?

That does admittedly look a bit odd, that assertion can't be reached if earm is
null since we've already dereferenced it by then.  I'll have another look after
coffee but something along the lines of your patch looks right (or just remove
the Assertion perhaps).

--
Daniel Gustafsson






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Assignment before assert
@ 2025-02-14 05:44  Michael Paquier <michael@paquier.xyz>
  parent: Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael Paquier @ 2025-02-14 05:44 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Dmitry Koval <d.koval@postgrespro.ru>; pgsql-hackers

On Fri, Feb 14, 2025 at 12:15:40AM +0100, Daniel Gustafsson wrote:
> > On 13 Feb 2025, at 18:08, Dmitry Koval <d.koval@postgrespro.ru> wrote:
> > 
> > Hi!
> > Function EvalPlanQualFetchRowMark contains an assignment
> > 
> > ExecRowMark *erm = earm->rowmark;
> > 
> > before assert
> > 
> > Assert(earm != NULL);
> > 
> > Maybe these lines need to be swapped?
> 
> That does admittedly look a bit odd, that assertion can't be reached if earm is
> null since we've already dereferenced it by then.  I'll have another look after
> coffee but something along the lines of your patch looks right (or just remove
> the Assertion perhaps).

Accessing earm->rowmark is one thing, assuming that earm should never
be NULL is a different one.  Looking at 27cc7cd2bc8a that has
introduced this assertion, the proposed patch makes sense to me.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Assignment before assert
@ 2025-02-14 11:46  Daniel Gustafsson <daniel@yesql.se>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 4+ messages in thread

From: Daniel Gustafsson @ 2025-02-14 11:46 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Dmitry Koval <d.koval@postgrespro.ru>; pgsql-hackers

> On 14 Feb 2025, at 06:44, Michael Paquier <michael@paquier.xyz> wrote:

> the proposed patch makes sense to me.

Committed, with a backpatch down to 13.

--
Daniel Gustafsson






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2025-02-14 11:46 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-13 17:08 Assignment before assert Dmitry Koval <d.koval@postgrespro.ru>
2025-02-13 23:15 ` Daniel Gustafsson <daniel@yesql.se>
2025-02-14 05:44   ` Michael Paquier <michael@paquier.xyz>
2025-02-14 11:46     ` Daniel Gustafsson <daniel@yesql.se>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox