check_recovery_target_lsn() does a PG_CATCH without a throw

Andres Freund <andres@anarazel.de>

From: Andres Freund <andres@anarazel.de>
To: pgsql-hackers@postgresql.org, Peter Eisentraut <peter_e@gmx.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2019-06-11T06:11:15Z
Lists: pgsql-hackers
Hi,

While working on fixing [1] I noticed that 2dedf4d9a899 "Integrate
recovery.conf into postgresql.conf" added two non-rethrowing PG_CATCH
uses. That's not OK. See

https://www.postgresql.org/message-id/1676.1548726280%40sss.pgh.pa.us
https://postgr.es/m/20190206160958.GA22304%40alvherre.pgsql
etc.

static bool
check_recovery_target_time(char **newval, void **extra, GucSource source)
{
    if (strcmp(*newval, "") != 0)
    {
        TimestampTz time;
        TimestampTz *myextra;
        MemoryContext oldcontext = CurrentMemoryContext;

        /* reject some special values */
        if (strcmp(*newval, "epoch") == 0 ||
            strcmp(*newval, "infinity") == 0 ||
            strcmp(*newval, "-infinity") == 0 ||
            strcmp(*newval, "now") == 0 ||
            strcmp(*newval, "today") == 0 ||
            strcmp(*newval, "tomorrow") == 0 ||
            strcmp(*newval, "yesterday") == 0)
        {
            return false;
        }

        PG_TRY();
        {
            time = DatumGetTimestampTz(DirectFunctionCall3(timestamptz_in,
                                                           CStringGetDatum(*newval),
                                                           ObjectIdGetDatum(InvalidOid),
                                                           Int32GetDatum(-1)));
        }
        PG_CATCH();
        {
            ErrorData  *edata;

            /* Save error info */
            MemoryContextSwitchTo(oldcontext);
            edata = CopyErrorData();
            FlushErrorState();

            /* Pass the error message */
            GUC_check_errdetail("%s", edata->message);
            FreeErrorData(edata);
            return false;
        }
        PG_END_TRY();

same in check_recovery_target_lsn.

I'll add an open item.

Greetings,

Andres Freund

[1] CALDaNm1KXK9gbZfY-p_peRFm_XrBh1OwQO1Kk6Gig0c0fVZ2uw@mail.gmail.com



Commits

  1. Don't call data type input functions in GUC check hooks