Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN4zK-00025U-F5 for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Sep 2020 02:03:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kN4zG-00049s-6w for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Sep 2020 02:03:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN4zE-00047k-Ez for pgsql-hackers@lists.postgresql.org; Tue, 29 Sep 2020 02:03:26 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN4zA-0001pv-D4 for pgsql-hackers@lists.postgresql.org; Tue, 29 Sep 2020 02:03:23 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id B25C19EF; Mon, 28 Sep 2020 22:03:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 28 Sep 2020 22:03:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=1Sw1yhB8gk1hx1p9VIwS0Bo9VwO w5qzMcZfGKP1hKcg=; b=IMkS/xvlQrLDUPzuOMvw1SRMYnofWhdlgBceqK5vNS3 ImEUyu038ta8D0wkUdaiDzS9Zfd8R7x/YwnG0P4rE41wtqsFWDcYxJ2C9qzFMyo1 UCBiHwfrA/Emabxaw+Az4I0PDxWp/l7HvtzNDY3W/4Tu7pt/qn+Suhrb5zGMMIrh CAstICHa5Ld68v4TTOTxCLomQELnvgSdPL5Txu8YxN67XBK9ZkMr/oFWB5UIxRDL 399YTsTOwoRjo6b0MIhwmgx+Lj7YzQpe0y2PH2W0SDRP6q9PhF2Frf6KmfaYxT9d JLzMnhcjdEXSKlbR+IteObE5iOSh7QDeKCDmr3RVYSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=1Sw1yh B8gk1hx1p9VIwS0Bo9VwOw5qzMcZfGKP1hKcg=; b=DtXW2FL0orba1XMHa965ab V8Lbit6rYU9di337FCB0vStzPQWItPUjweJwfb4RjfbZTqbHyUmV4Deaug3J12Fr XhOxDpuGJU8CxPZD9U0dZzCq2SbUeciyjnpePsEy9aQwW6IQ3Fh74zzkvVskY+I1 gy629JM3XfzbF6bxjNaPu33VnfhFxTg8L2TcqdBhaG88xT8LVT54s8NBjSXS9f3t /MJcTK3opZxV6gOUWzG9L/fpAXgNAxnff8yLh8zyp1SLBcRkYoRfRH209zIThNjL 0by6FkWWcGYOBi/7J09BpjtNGC3WkmmdawyHqbGC61HjCK6vVf62qztQKqL9Ny4A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdejgdehhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvdegudeuhfdtueeltedtveejheeh ieevueeigeelteegleejleeiueeiheegvefhnecukfhppeduuddurddutddvrddukedtrd dukeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep mhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id D29FD3064674; Mon, 28 Sep 2020 22:03:15 -0400 (EDT) Date: Tue, 29 Sep 2020 11:03:12 +0900 From: Michael Paquier To: Tom Lane Cc: Postgres hackers Subject: Re: __pg_log_level in anonynous enum should be initialized? (Was: pgsql: Change SHA2 implementation based on OpenSSL to use EVP digest ro) Message-ID: <20200929020312.GA10200@paquier.xyz> References: <20200928073330.GC2316@paquier.xyz> <300644.1601311769@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="yNb1oOkm5a9FJOVX" Content-Disposition: inline In-Reply-To: <300644.1601311769@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --yNb1oOkm5a9FJOVX Content-Type: multipart/mixed; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 28, 2020 at 12:49:29PM -0400, Tom Lane wrote: > I experimented and confirmed that explicitly initializing __pg_log_level > would suppress this build error on prairiedog. However, I'm not sure > that doing so is a good idea, because it seems to me that this animal > has accidentally saved us from a serious design error. IMO it is quite > unacceptable for libpq to contain either a forced write to stderr or a > forced exit(1). It should be reporting the failure back to the calling > application, instead. So the error handling in this patch needs to be > reconsidered. Yeah, I have arrived at the same conclusion after a night of sleep and after looking at the OpenSSL code for a couple of hours to see if it would be possible to use a static state of EVP and not have to do all this error handling. But, we are going to need much more than that, so I have reverted the patch: - Any allocation done with EVP is going to need a callback for the cleanup in the backend, because we basically have to do the allocation directly in OpenSSL. Not only for the higher EVP structure we get to use in sha2_openssl.c, but also for some other parts at lower level, like MD with EVP_MD_CTX_FLAG_NO_INIT. - It will be better to have those routines return a status and just let the caller handle the error. This impacts the internals of SCRAM, particularly for the secret and internal HMAC implementations. And this needs a change in the fallback implementation. - We will most likely need to split the existing init and destroy routines so as the initial allocation and final free happen in different paths, even for the fallback implementation so as we have a 1:1 mapping with what OpenSSL does. > Since prairiedog is not likely to be around forever, I propose that > we ought to enforce this going forward by arranging for common/logging.c > to not get built into the libpgcommon_shlib library variant. Agreed. This makes sense in the long term, so attached is a proposal of patch. I did not really see the point in complicating the MSVC scripts for that though. The new variable names look natural to me like that, the new comment may need some tweaks. -- Michael --8t9RHnE3ZwKMSgU+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="common-shlib-split.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/common/Makefile b/src/common/Makefile index f281762885..d0bbaefb1e 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -88,13 +88,18 @@ OBJS_COMMON +=3D sha2.o endif =20 # A few files are currently only built for frontend, not server -# (Mkvcbuild.pm has a copy of this list, too) +# (Mkvcbuild.pm has a copy of this list, too). logging.c is +# explicitely excluded from the shared library as it enforces some +# global state used for error reporting, that should never be used +# by libpq or similar. OBJS_FRONTEND =3D \ $(OBJS_COMMON) \ fe_memutils.o \ - logging.o \ restricted_token.o \ sprompt.o +OBJS_PGCOMMON =3D \ + $(OBJS_FRONTEND) \ + logging.o =20 # foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c OBJS_SHLIB =3D $(OBJS_FRONTEND:%.o=3D%_shlib.o) @@ -121,7 +126,7 @@ uninstall: rm -f '$(DESTDIR)$(libdir)/libpgcommon.a' rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a' =20 -libpgcommon.a: $(OBJS_FRONTEND) +libpgcommon.a: $(OBJS_PGCOMMON) rm -f $@ $(AR) $(AROPT) $@ $^ =20 @@ -177,7 +182,7 @@ $(RYU_OBJS): CFLAGS +=3D $(PERMIT_DECLARATION_AFTER_STA= TEMENT) # kwlist_d.h is in the distribution tarball, so it is not cleaned here. clean distclean: rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a - rm -f $(OBJS_FRONTEND) $(OBJS_SHLIB) $(OBJS_SRV) + rm -f $(OBJS_PGCOMMON) $(OBJS_SHLIB) $(OBJS_SRV) =20 maintainer-clean: distclean rm -f kwlist_d.h --8t9RHnE3ZwKMSgU+-- --yNb1oOkm5a9FJOVX Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl9yleAACgkQnvQgOdby QH2epQ//Zx+Mny1W0vO22SOvS2uh3KV37tHG7AGDQEkoWE2WpoeI06OB2pjKSGFw W/63QrRB7+HNUJ9R3iFy7tKimiY6dH2mwFVq6PCkbQepAk4t8aK531SzrsaQtHpV zzJhPBni28C/A29DpNRkclZMVPcf8K8yiEk3n+5WrYoZ0zO3glCQUemUkeSxJaqz 2PGLv7goJW8HOtNzbA0RaPwQ5iCgsQt3owe4wU+Znhjzj3+MD+dSO20ov7zYC+EO 9adl96dfacm08IhaZxE/gDjhd2m8Tinln/qn7nIhX/gowfCEPx8Yi7tH3S5ZiHE5 1RM5JsfYONYhelxe3gaxo0Bx/5z2AoKmgnKtf4Caz/Fz632AU0jzslZCXbCAUm1L v3NMKtj2le/vzKd2f49y54LIiW8LE6euultIXlZ1awVStFLFg16pnFzb4gvP629F yZrvlEhatIarq1PbiQJgJ2OWlrkotzEPfZr4lVkYBCFXb4BcP2Jaq2N9JNjxzcRw w8TrPoTD4qcKYLXuigpung3CQoCpCifwvo2lAArB2HcfiX/IrECdMJwOuf2wWize NYxeg4bdaXifLcvbKhz6aXuu2FL77ztZkKJk5jvoHJmYiHfgaTAAtAba3OP05Nkc HPv+TpXronws6/xFYnA8hk/K9GJelMVoJnHQEW7t4t57GUr8zLo= =UHW8 -----END PGP SIGNATURE----- --yNb1oOkm5a9FJOVX--