pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBackwards boolean logic?
2+ messages / 2 participants
[nested] [flat]
* Backwards boolean logic?
@ 2019-03-19 13:27 Derek Viljoen <derekv@infinite.io>
2019-03-19 16:59 ` Re: Backwards boolean logic? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Derek Viljoen @ 2019-03-19 13:27 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
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.
If that is not correct, then the comments should be updated to reflect the
code.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Backwards boolean logic?
2019-03-19 13:27 Backwards boolean logic? Derek Viljoen <derekv@infinite.io>
@ 2019-03-19 16:59 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2019-03-19 16:59 UTC (permalink / raw)
To: Derek Viljoen <derekv@infinite.io>; +Cc: pgsql-bugs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-03-19 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 13:27 Backwards boolean logic? Derek Viljoen <derekv@infinite.io>
2019-03-19 16:59 ` Tom Lane <tgl@sss.pgh.pa.us>
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