pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Produce compiler errors if errno is referenced inside elog/erepo
Date: Sat, 11 Aug 2018 15:24:06 +0000
Message-ID: <E1foVkM-0006pJ-GA@gemulon.postgresql.org> (raw)

Produce compiler errors if errno is referenced inside elog/ereport calls.

It's often unsafe to reference errno within an elog/ereport call, because
there are a lot of sub-functions involved and they might not all preserve
errno.  (This is why we support the %m format spec: it works off a value
of errno captured before we execute any potentially-unsafe functions in
the arguments.)  Therefore, we have a project policy not to use errno
there.

This patch adds a hack to cause an (admittedly obscure) compiler error
for such unsafe usages.  With the current code, the error will only be seen
on Linux, macOS, and FreeBSD, but that should certainly be enough to catch
mistakes in the buildfarm if they somehow get missed earlier.

In addition, fix some places in src/common/exec.c that trip the error.
I think these places are actually all safe, but it's simple enough to
avoid the error by capturing errno manually, and doing so is good
future-proofing in case these call sites get any more complicated.

Thomas Munro (exec.c fixes by me)

Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a2a8acd15217b1e355c083a41da4dc5c7f35b30b

Modified Files
--------------
src/common/exec.c        | 27 +++++++++++++++++++++------
src/include/utils/elog.h | 21 +++++++++++++++++++++
2 files changed, 42 insertions(+), 6 deletions(-)



Message-ID: <E1foVkM-0006pJ-GA@gemulon.postgresql.org>
Permalink:  ../E1foVkM-0006pJ-GA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1foVkM-0006pJ-GA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Produce compiler errors if errno is referenced inside elog/erepo
  In-Reply-To: <E1foVkM-0006pJ-GA@gemulon.postgresql.org>
  References: <E1foVkM-0006pJ-GA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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