pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: PanBian <bianpan2016@163.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14929: Unchecked AllocateDir() return value in restoreTwoPhaseData()
Date: Mon, 27 Nov 2017 10:08:58 -0500
Message-ID: <17000.1511795338@sss.pgh.pa.us> (raw)
In-Reply-To: <20171127114410.GA30545@bp>
References: <20171127093107.1473.70477@wrigleys.postgresql.org>
	<CAB7nPqR0ui2hjmSTJ0PYc-YMOs_r7GX2OL9ehR07JCytxZex_w@mail.gmail.com>
	<20171127114410.GA30545@bp>

PanBian <bianpan2016@163.com> writes:
> On Mon, Nov 27, 2017 at 07:53:30PM +0900, Michael Paquier wrote:
>> You are missing the fact that ReadDir goes through ReadDirExtended,
>> which drops an ERROR log if the folder allocated is NULL.

> You are right. Its my carelessness. ReadDir will not return back on a
> NULL dir parameter. The code is bug free. Sorry for the trouble.

There are some issues here, though:

1. twophase.c does this:

    cldir = AllocateDir(TWOPHASE_DIR);
    LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
    while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
    {

which is flat out wrong because LWLockAcquire might well clobber errno.
I don't see any good reason why we couldn't just swap the order of
those two calls.

2. basebackup.c and some other places do things like

        dir = AllocateDir("pg_wal");
        if (!dir)
            ereport(ERROR,
                    (errmsg("could not open directory \"%s\": %m", "pg_wal")));
        while ((de = ReadDir(dir, "pg_wal")) != NULL)

Not only is this a waste of code, because the error message is no better
than what ReadDir would provide, but it's wrong because it omits
errcode_for_file_access(), causing the SQLSTATE to be reported as XX000.
There are other places that are even lazier and use elog(), failing
translatability as well as the errcode test.

There might be some other problems I missed in a quick scan.

So there's definitely room for a cleanup patch here, but the originally
proposed change isn't it.

			regards, tom lane




view thread (10+ messages)  latest in thread

Message-ID: <17000.1511795338@sss.pgh.pa.us>
Permalink:  ../17000.1511795338@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17000.1511795338@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bianpan2016@163.com, michael.paquier@gmail.com, Langote_Amit_f8@lab.ntt.co.jp
  Subject: Re: BUG #14929: Unchecked AllocateDir() return value in restoreTwoPhaseData()
  In-Reply-To: <17000.1511795338@sss.pgh.pa.us>
  References: <20171127093107.1473.70477@wrigleys.postgresql.org> <CAB7nPqR0ui2hjmSTJ0PYc-YMOs_r7GX2OL9ehR07JCytxZex_w@mail.gmail.com> <20171127114410.GA30545@bp> <17000.1511795338@sss.pgh.pa.us>

* 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