pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Derek Viljoen <derekv@infinite.io>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Backwards boolean logic?
Date: Tue, 19 Mar 2019 12:59:56 -0400
Message-ID: <20764.1553014796@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJVskpVMpF4hzFW+ORwV_YSrUa6d=i=E3pUAv6mjpNNhqL4SVQ@mail.gmail.com>
References: <CAJVskpVMpF4hzFW+ORwV_YSrUa6d=i=E3pUAv6mjpNNhqL4SVQ@mail.gmail.com>

Derek Viljoen <derekv@infinite.io> writes:
> In hba.c in check_hba() function:
>             /* Check SSL state */
>             if (port->ssl_in_use)
>             {
>                 /* Connection is SSL, match both "host" and "hostssl" */
>                 if (hba->conntype == ctHostNoSSL)
>                     continue;
>             }
>             else
>             {
>                 /* Connection is not SSL, match both "host" and "hostnossl"
> */
>                 if (hba->conntype == ctHostSSL)
>                     continue;
>             }

> It looks to me like conntype should be reversed in this code block.

I think people would have noticed if this were backwards ;-)

Possibly what's confusing you is that the "continue" statements execute
when we don't have a "match"; if the hba entry does match the connection
in this respect, then we fall through to keep on examining the entry.

> If that is not correct, then the comments should be updated to reflect the
> code.

What would you propose exactly?  Perhaps we could s/match/accept/ but
I'm not sure that's any clearer.

The bigger picture here is that all the "continue" statements in this
loop should be read as "this entry fails to match, so try the next one".
If there's any comment change needed, I'd be inclined to think about
making that more explicit; but it's an awfully common coding pattern.

			regards, tom lane




view thread (2+ messages)

Message-ID: <20764.1553014796@sss.pgh.pa.us>
Permalink:  ../20764.1553014796@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20764.1553014796@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, derekv@infinite.io
  Subject: Re: Backwards boolean logic?
  In-Reply-To: <20764.1553014796@sss.pgh.pa.us>
  References: <CAJVskpVMpF4hzFW+ORwV_YSrUa6d=i=E3pUAv6mjpNNhqL4SVQ@mail.gmail.com> <20764.1553014796@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