Re: ereport bug

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dmitry Voronin <carriingfate92(at)yandex(dot)ru>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ereport bug
Date: 2015-01-12 15:17:22
Message-ID: 24065.1421075842@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dmitry Voronin <carriingfate92(at)yandex(dot)ru> writes:
> <div><div><div><div data-lang="2"><div>Hello, postgresmen!</div><div></div><div>I found incorrect execution of ereport() macro. <br />If we pass into ereport() function 2 or more arguments, the macro errcontext does not correct execute. So, ereport() call stack is:</div><div></div><div>errstart<br />errcontext_msg<br />set_errcontext_domain<br />errmsg<br />errfinish<br />pg_unreachable</div><div></div><div><span lang="en"><span>This bug</span> <span>causes that error messages (for example, in PL/TCL) are </span></span><span lang="en"><span>not localized.<br /><br />Solutions:<br />- Wrap all errcontext() macro in </span></span><span lang="en"><span><span lang="en"><span>brackets, that is errcontext("error message %s", "end message") -&gt; (</span></span></span></span><span lang="en"><span><span lang="en"><span>errcontext("error message %s", "end message"))</span></span></span></span></div><div><span lang="en"><span><span lang="en"><span>- Rewrite this macro</span></spa!
n></span></span></div><div><span lang="en"><span><span lang="en"><span>- ???</span></span></span></span></div><div></div><div><span lang="en"><span>I am attaching</span> <span>to this letter</span> <span>a test case</span> <span>that shows</span> <span>the behavior errcontext() macro and the way to fix it.<br /></span></span></div><div><br />I am using postgresql 9.4 and test it on gcc 4.7 and gcc 4.8.1.<br /><br /></div><div>-- Best regards, Dmitry Voronin</div></div></div></div></div>

(Please don't post HTML-only mail to the PG mailing lists ...)

Hm ... the initial thought was that errcontext would never be used
directly in an ereport() macro, but you're right that we now have some
places that violate that rule. So the comma expression turns into a
couple of arguments to errfinish, meaning the order of evaluation becomes
compiler-dependent which is bad.

I think the easiest fix is to have errstart initialize context_domain
to the same value as domain. The order of evaluation is still
compiler-dependent, but it no longer matters because any errcontext
calls occurring textually within an ereport should be trying to select
the same domain as the ereport anyway.

regards, tom lane

In response to

  • ereport bug at 2015-01-12 11:27:29 from Dmitry Voronin

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2015-01-12 15:40:26 Latches and barriers
Previous Message Stephen Frost 2015-01-12 14:24:43 Re: INSERT ... ON CONFLICT UPDATE and RLS