From: Michael Paquier <michael@paquier.xyz>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Subject: Some remaining htonl() and ntohl() calls in the code
Date: Wed, 14 Oct 2020 14:53:03 +0900
Message-ID: <20201014055303.GG3349@paquier.xyz> (raw)
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
Attachments:htonl-fix-v1.patch (text/x-diff, 2.9K) downloaddiff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.cindex 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 += input.length;
/* 4 network-order bytes of length, then payload */
- netlen = htonl(output.length);+ netlen = pg_hton32(output.length);
memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
PqGSSSendLength += sizeof(uint32);
@@ -323,7 +323,7 @@ be_gssapi_read(Port *port, void *ptr, size_t len)
}
/* Decode the packet length and check for overlength packet */
- input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);+ input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
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 = ntohl(*(uint32 *) PqGSSRecvBuffer);+ input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
/* Done with the length, reset our buffer */
PqGSSRecvLength = 0;
@@ -567,7 +567,7 @@ secure_open_gssapi(Port *port)
*/
if (output.length > 0)
{
- uint32 netlen = htonl(output.length);+ uint32 netlen = pg_hton32(output.length);
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.cindex 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 += input.length;
/* 4 network-order bytes of length, then payload */
- netlen = htonl(output.length);+ netlen = pg_hton32(output.length);
memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
PqGSSSendLength += sizeof(uint32);
@@ -346,7 +346,7 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
}
/* Decode the packet length and check for overlength packet */
- input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);+ input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
{
@@ -589,7 +589,7 @@ pqsecure_open_gss(PGconn *conn)
*/
/* Get the length and check for over-length packet */
- input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);+ input.length = 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)
}
/* Queue the token for writing */
- netlen = htonl(output.length);+ netlen = pg_hton32(output.length);
memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
PqGSSSendLength += sizeof(uint32);
signature.asc (application/pgp-signature, 832B) download
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-hackers@postgresql.org
Cc: michael@paquier.xyz
Subject: Re: Some remaining htonl() and ntohl() calls in the code
In-Reply-To: <20201014055303.GG3349@paquier.xyz>
References: <20201014055303.GG3349@paquier.xyz>
* 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