#include "postgres.h"
 
-#include "be-gssapi-common.h"
+#include <unistd.h>
 
+#include "be-gssapi-common.h"
 #include "libpq/auth.h"
 #include "libpq/libpq.h"
 #include "libpq/libpq-be.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 
-#include <unistd.h>
-
 
 /*
  * Handle the encryption/decryption of data using GSSAPI.
            pg_GSS_error(FATAL, gettext_noop("GSSAPI wrap error"), major, minor);
 
        if (conf == 0)
-           ereport(FATAL, (errmsg("GSSAPI did not provide confidentiality")));
+           ereport(FATAL,
+                   (errmsg("GSSAPI did not provide confidentiality")));
 
        if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
-           ereport(FATAL, (errmsg("GSSAPI tried to send packet of size: %ld", output.length)));
+           ereport(FATAL,
+                   (errmsg("server tried to send oversize GSSAPI packet: %zu bytes",
+                           (size_t) output.length)));
 
        bytes_encrypted += input.length;
        bytes_to_encrypt -= input.length;
 
        /* Check for over-length packet */
        if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
-           ereport(FATAL, (errmsg("Over-size GSSAPI packet sent by the client.")));
+           ereport(FATAL,
+                   (errmsg("oversize GSSAPI packet sent by the client: %zu bytes",
+                           (size_t) input.length)));
 
        /*
         * Read as much of the packet as we are able to on this call into
                         major, minor);
 
        if (conf == 0)
-           ereport(FATAL, (errmsg("GSSAPI did not provide confidentiality")));
+           ereport(FATAL,
+                   (errmsg("GSSAPI did not provide confidentiality")));
 
        memcpy(PqGSSResultBuffer, output.value, output.length);
 
         * Verify on our side that the client doesn't do something funny.
         */
        if (input.length > PQ_GSS_RECV_BUFFER_SIZE)
-           ereport(FATAL, (errmsg("Over-size GSSAPI packet sent by the client: %ld", input.length)));
+           ereport(FATAL,
+                   (errmsg("oversize GSSAPI packet sent by the client: %zu bytes",
+                           (size_t) input.length)));
 
        /*
         * Get the rest of the packet so we can pass it to GSSAPI to accept
            uint32      netlen = htonl(output.length);
 
            if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
-               ereport(FATAL, (errmsg("GSSAPI tried to send oversize packet")));
+               ereport(FATAL,
+                       (errmsg("server tried to send oversize GSSAPI packet: %zu bytes",
+                               (size_t) output.length)));
 
            memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
            PqGSSSendPointer += sizeof(uint32);
 
 #include "libpq-fe.h"
 #include "libpq-int.h"
 #include "fe-gssapi-common.h"
-
 #include "port/pg_bswap.h"
 
 /*
        }
        else if (conf == 0)
        {
-           printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
-                                                                "GSSAPI did not provide confidentiality\n"));
+           printfPQExpBuffer(&conn->errorMessage,
+                             libpq_gettext("GSSAPI did not provide confidentiality\n"));
            goto cleanup;
        }
 
        if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
        {
-           printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
-                                                                "GSSAPI attempt to send oversize packet\n"));
+           printfPQExpBuffer(&conn->errorMessage,
+                             libpq_gettext("client tried to send oversize GSSAPI packet: %zu bytes\n"),
+                             (size_t) output.length);
            goto cleanup;
        }
 
        /* Check for over-length packet */
        if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
        {
-           printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
-                                                                "GSSAPI did not provide confidentiality\n"));
+           printfPQExpBuffer(&conn->errorMessage,
+                             libpq_gettext("GSSAPI did not provide confidentiality\n"));
            ret = -1;
            goto cleanup;
        }
        }
        else if (conf == 0)
        {
-           printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
-                                                                "GSSAPI did not provide confidentiality\n"));
+           printfPQExpBuffer(&conn->errorMessage,
+                             libpq_gettext("GSSAPI did not provide confidentiality\n"));
            ret = -1;
            goto cleanup;
        }
 
            PqGSSRecvLength += ret;
 
-           printfPQExpBuffer(&conn->errorMessage, "%s", PqGSSRecvBuffer + 1);
+           printfPQExpBuffer(&conn->errorMessage, "%s\n", PqGSSRecvBuffer + 1);
 
            return PGRES_POLLING_FAILED;
        }
        input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
        if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
        {
-           printfPQExpBuffer(&conn->errorMessage, libpq_gettext("Over-size GSSAPI packet sent by the server: %ld"), input.length);
+           printfPQExpBuffer(&conn->errorMessage,
+                             libpq_gettext("oversize GSSAPI packet sent by the server: %zu bytes\n"),
+                             (size_t) input.length);
            return PGRES_POLLING_FAILED;
        }