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 1kSZj2-00009j-Ap for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Oct 2020 05:53:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSZiy-0005zp-TE for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Oct 2020 05:53:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSZix-0005zi-Rb for pgsql-hackers@lists.postgresql.org; Wed, 14 Oct 2020 05:53:20 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSZip-0004eB-J0 for pgsql-hackers@lists.postgresql.org; Wed, 14 Oct 2020 05:53:19 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 3E4FEA63 for ; Wed, 14 Oct 2020 01:53:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 14 Oct 2020 01:53:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:subject:message-id:mime-version:content-type; s= fm3; bh=dg8VF4xTvA6WdyL8GU2/J9NTWxuSpqRvZafix3f0cKY=; b=p1IT+DUS D7cpU1XP0m6xSywczzm3JERHkyEW6iOUinoUKy7yMQR48FkP7wJmhRxiVClM/JK1 Y2Bo6FMIhv5TT1KKvvNDBDEmwdLEIj5venNq2FG5r2a0QRD4c1662zmcEA/xo2V7 On2eCZ+lWBOBhO8o6yGoG/Ml+x+J9Hpo2afvAmVWRqWv9cre0ASWTyBZWZwky8+b TnUmq1/t9BMDUsXaCfvvUZd1UUfiwmN1gQck8UCC3n+gRBIV9o8KZDyfZeiUrKkR 1eJwiFPFe7eWFSzFo3gVq0CcTFkLktZ3lmq54URU3++ZThCAt9hiYWP8iNmlJ32y XkPN8R44GOLQUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=dg8VF4xTvA6WdyL8GU2/J9NTWxuSp qRvZafix3f0cKY=; b=kgzOIEVW7qfCV+9IqGkJ47dy4VLwdOZd5eHYy65p9Ljln HKBwTFiYoUJTPvBVl+VNlE8yR2U+wU59ANmNXz2fBayzYHLHfjDvr9KTZwn9oZ9U b20kXxEGlRakVzD59gLChFIvmdwfmRJdG5X4edkrYUs57qORQECrx47tVmHCWchs aQLkTgo46nQ6nc4yOUeqGw73zeVvY2jMwaFIF/5HA4exUChYCram9CBfe4Nnmd+q 467MrUSxpEUAAXqmsmWxsNejgCyvjt20Ag7hTEEiR9AZVlAeQyQyq1t0jLp8ZI8s bl0j7XJxZJKlAsYW2xqVMB1JeYBItJoMn5ODy29Yg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedriedtgddutddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkgggtugesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvtdffteegtdfhuefgvedvtdejgfeu gfeggfejgfdvhefgfeevieektdelkefhgfenucfkphepudduuddruddtvddrudektddrud ekheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehm ihgthhgrvghlsehprghquhhivghrrdighiii 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 AEB503280059 for ; Wed, 14 Oct 2020 01:53:06 -0400 (EDT) Date: Wed, 14 Oct 2020 14:53:03 +0900 From: Michael Paquier To: Postgres hackers Subject: Some remaining htonl() and ntohl() calls in the code Message-ID: <20201014055303.GG3349@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2xeD/fx0+7k8I/QN" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --2xeD/fx0+7k8I/QN Content-Type: multipart/mixed; boundary="LZFKeWUZP29EKQNE" Content-Disposition: inline --LZFKeWUZP29EKQNE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, Since 510b8cbf, we have in-core equivalents for htonl(), ntohl() & co through pg_bswap.h that allows to compile with a built-in function if the compiler used has one. All the existing calls in the code tree have been changed with 0ba99c84 for performance reasons (except the libpq examples), however the FE/BE code of GSSAPI encryption code did not get this call in b0b39f7. I think that we had better switch to the built-ins functions as well for this case. The argument of consistency matters here, but also perhaps the argument of performance, where it may not be easy to measure a difference. Attached is a patch to do the switch. None of the files changed include arpa/inet.h. Any thoughts? Thanks, -- Michael --LZFKeWUZP29EKQNE Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="htonl-fix-v1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-se= cure-gssapi.c index 64427f185b..5a73302b7b 100644 --- a/src/backend/libpq/be-secure-gssapi.c +++ b/src/backend/libpq/be-secure-gssapi.c @@ -209,7 +209,7 @@ be_gssapi_write(Port *port, void *ptr, size_t len) PqGSSSendConsumed +=3D input.length; =20 /* 4 network-order bytes of length, then payload */ - netlen =3D htonl(output.length); + netlen =3D pg_hton32(output.length); memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32)); PqGSSSendLength +=3D sizeof(uint32); =20 @@ -323,7 +323,7 @@ be_gssapi_read(Port *port, void *ptr, size_t len) } =20 /* Decode the packet length and check for overlength packet */ - input.length =3D ntohl(*(uint32 *) PqGSSRecvBuffer); + input.length =3D pg_ntoh32(*(uint32 *) PqGSSRecvBuffer); =20 if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)) ereport(FATAL, @@ -509,7 +509,7 @@ secure_open_gssapi(Port *port) /* * Get the length for this packet from the length header. */ - input.length =3D ntohl(*(uint32 *) PqGSSRecvBuffer); + input.length =3D pg_ntoh32(*(uint32 *) PqGSSRecvBuffer); =20 /* Done with the length, reset our buffer */ PqGSSRecvLength =3D 0; @@ -567,7 +567,7 @@ secure_open_gssapi(Port *port) */ if (output.length > 0) { - uint32 netlen =3D htonl(output.length); + uint32 netlen =3D pg_hton32(output.length); =20 if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32)) ereport(FATAL, diff --git a/src/interfaces/libpq/fe-secure-gssapi.c b/src/interfaces/libpq= /fe-secure-gssapi.c index 1994e9f615..bfc0f55214 100644 --- a/src/interfaces/libpq/fe-secure-gssapi.c +++ b/src/interfaces/libpq/fe-secure-gssapi.c @@ -226,7 +226,7 @@ pg_GSS_write(PGconn *conn, const void *ptr, size_t len) PqGSSSendConsumed +=3D input.length; =20 /* 4 network-order bytes of length, then payload */ - netlen =3D htonl(output.length); + netlen =3D pg_hton32(output.length); memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32)); PqGSSSendLength +=3D sizeof(uint32); =20 @@ -346,7 +346,7 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len) } =20 /* Decode the packet length and check for overlength packet */ - input.length =3D ntohl(*(uint32 *) PqGSSRecvBuffer); + input.length =3D pg_ntoh32(*(uint32 *) PqGSSRecvBuffer); =20 if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)) { @@ -589,7 +589,7 @@ pqsecure_open_gss(PGconn *conn) */ =20 /* Get the length and check for over-length packet */ - input.length =3D ntohl(*(uint32 *) PqGSSRecvBuffer); + input.length =3D pg_ntoh32(*(uint32 *) PqGSSRecvBuffer); if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)) { printfPQExpBuffer(&conn->errorMessage, @@ -688,7 +688,7 @@ pqsecure_open_gss(PGconn *conn) } =20 /* Queue the token for writing */ - netlen =3D htonl(output.length); + netlen =3D pg_hton32(output.length); =20 memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32)); PqGSSSendLength +=3D sizeof(uint32); --LZFKeWUZP29EKQNE-- --2xeD/fx0+7k8I/QN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl+Gkj8ACgkQnvQgOdby QH2v/g/+LXvWlE0zd3oqCiHKDlAVZAUYHX6uShGGzYv8ODK17Qj/+w8nDzuWJH+D 2oEHg7tNDYbxXyJEWPMPtv5siRjqopGYOLdGNH3lUJyeAooWcugCLf7ka+rQPvf2 g3YrOH+mPycAieIWO3qNXVkEMmU/dvdSzrtxOedgzTI0qmkCEbBKvjo8ijGoLQoP GDKDk6ot4skiqgry6tZgMgaeb1KtcJILeRdKQ7XLNoaTCOCWV90m6vlkxxmbVj5c 7Cb1QL3oQOLpBukGT+RxE3FC9laJdpqlKH5239oMgGgm+M9Kh1e/sskfJOnMw113 D1xPnWIgcLAgWfQVr9iWWiQCep5FlKT6Eez2/Q+fij3Yov83ucxvNThy+b9cN6dg 2O1Kukp3oerjOiWLLQTIFlREI+NI6jX8+jbfzjOH/PcqFsG3BvgmviBzgZ3D5UQi 0KCmyiMhKrzBHDyTfMMbxqoZiMs00kt+Id6nY3cbnWbb1CXNM7UBPJW4NFzlUhIa 0VxEA/nu7z5hOy9QQpRp5i2upSBl3fHZ01bMIboZUZmxABhkGRZgkcmsKsc1KfNa 9gnfAWLxH6nRvOqUmVyIivugYKgALlkaSpz/dP5L8jqFvN7evDFp1uuPresZi6e5 BFrfIl/e1/4fpJzaKkaK0vSlLtC+ff4+desIKKN+XXnYi+nMX4w= =DCeJ -----END PGP SIGNATURE----- --2xeD/fx0+7k8I/QN--