Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6I5r-0005hN-Ix for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Mar 2019 17:00:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h6I5q-0000L9-76 for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Mar 2019 17:00:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6I5p-0000B2-RJ for pgsql-bugs@lists.postgresql.org; Tue, 19 Mar 2019 17:00:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6I5n-0001o3-DM for pgsql-bugs@lists.postgresql.org; Tue, 19 Mar 2019 17:00:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x2JGxuZu020765; Tue, 19 Mar 2019 12:59:56 -0400 From: Tom Lane To: Derek Viljoen cc: pgsql-bugs@lists.postgresql.org Subject: Re: Backwards boolean logic? In-reply-to: References: Comments: In-reply-to Derek Viljoen message dated "Tue, 19 Mar 2019 08:27:41 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20763.1553014796.1@sss.pgh.pa.us> Date: Tue, 19 Mar 2019 12:59:56 -0400 Message-ID: <20764.1553014796@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Derek Viljoen 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