Skip to content

Commit 8cde7f4

Browse files
committed
Fix assorted minor bogosity in GSSAPI transport error messages.
I noted that some buildfarm members were complaining about %ld being used to format values that are (probably) declared size_t. Use %zu instead, and insert a cast just in case some versions of the GSSAPI API declare the length field differently. While at it, clean up gratuitous differences in wording of equivalent messages, show the complained-of length in all relevant messages not just some, include trailing newline where needed, adjust random deviations from project-standard code layout and message style, etc.
1 parent b4f96d6 commit 8cde7f4

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/backend/libpq/be-secure-gssapi.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414

1515
#include "postgres.h"
1616

17-
#include "be-gssapi-common.h"
17+
#include <unistd.h>
1818

19+
#include "be-gssapi-common.h"
1920
#include "libpq/auth.h"
2021
#include "libpq/libpq.h"
2122
#include "libpq/libpq-be.h"
2223
#include "libpq/pqformat.h"
2324
#include "miscadmin.h"
2425
#include "pgstat.h"
2526

26-
#include <unistd.h>
27-
2827

2928
/*
3029
* Handle the encryption/decryption of data using GSSAPI.
@@ -179,10 +178,13 @@ be_gssapi_write(Port *port, void *ptr, size_t len)
179178
pg_GSS_error(FATAL, gettext_noop("GSSAPI wrap error"), major, minor);
180179

181180
if (conf == 0)
182-
ereport(FATAL, (errmsg("GSSAPI did not provide confidentiality")));
181+
ereport(FATAL,
182+
(errmsg("GSSAPI did not provide confidentiality")));
183183

184184
if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
185-
ereport(FATAL, (errmsg("GSSAPI tried to send packet of size: %ld", output.length)));
185+
ereport(FATAL,
186+
(errmsg("server tried to send oversize GSSAPI packet: %zu bytes",
187+
(size_t) output.length)));
186188

187189
bytes_encrypted += input.length;
188190
bytes_to_encrypt -= input.length;
@@ -297,7 +299,9 @@ be_gssapi_read(Port *port, void *ptr, size_t len)
297299

298300
/* Check for over-length packet */
299301
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
300-
ereport(FATAL, (errmsg("Over-size GSSAPI packet sent by the client.")));
302+
ereport(FATAL,
303+
(errmsg("oversize GSSAPI packet sent by the client: %zu bytes",
304+
(size_t) input.length)));
301305

302306
/*
303307
* Read as much of the packet as we are able to on this call into
@@ -341,7 +345,8 @@ be_gssapi_read(Port *port, void *ptr, size_t len)
341345
major, minor);
342346

343347
if (conf == 0)
344-
ereport(FATAL, (errmsg("GSSAPI did not provide confidentiality")));
348+
ereport(FATAL,
349+
(errmsg("GSSAPI did not provide confidentiality")));
345350

346351
memcpy(PqGSSResultBuffer, output.value, output.length);
347352

@@ -492,7 +497,9 @@ secure_open_gssapi(Port *port)
492497
* Verify on our side that the client doesn't do something funny.
493498
*/
494499
if (input.length > PQ_GSS_RECV_BUFFER_SIZE)
495-
ereport(FATAL, (errmsg("Over-size GSSAPI packet sent by the client: %ld", input.length)));
500+
ereport(FATAL,
501+
(errmsg("oversize GSSAPI packet sent by the client: %zu bytes",
502+
(size_t) input.length)));
496503

497504
/*
498505
* Get the rest of the packet so we can pass it to GSSAPI to accept
@@ -538,7 +545,9 @@ secure_open_gssapi(Port *port)
538545
uint32 netlen = htonl(output.length);
539546

540547
if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
541-
ereport(FATAL, (errmsg("GSSAPI tried to send oversize packet")));
548+
ereport(FATAL,
549+
(errmsg("server tried to send oversize GSSAPI packet: %zu bytes",
550+
(size_t) output.length)));
542551

543552
memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
544553
PqGSSSendPointer += sizeof(uint32);

src/interfaces/libpq/fe-secure-gssapi.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "libpq-fe.h"
1717
#include "libpq-int.h"
1818
#include "fe-gssapi-common.h"
19-
2019
#include "port/pg_bswap.h"
2120

2221
/*
@@ -163,15 +162,16 @@ pg_GSS_write(PGconn *conn, const void *ptr, size_t len)
163162
}
164163
else if (conf == 0)
165164
{
166-
printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
167-
"GSSAPI did not provide confidentiality\n"));
165+
printfPQExpBuffer(&conn->errorMessage,
166+
libpq_gettext("GSSAPI did not provide confidentiality\n"));
168167
goto cleanup;
169168
}
170169

171170
if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
172171
{
173-
printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
174-
"GSSAPI attempt to send oversize packet\n"));
172+
printfPQExpBuffer(&conn->errorMessage,
173+
libpq_gettext("client tried to send oversize GSSAPI packet: %zu bytes\n"),
174+
(size_t) output.length);
175175
goto cleanup;
176176
}
177177

@@ -286,8 +286,8 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
286286
/* Check for over-length packet */
287287
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
288288
{
289-
printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
290-
"GSSAPI did not provide confidentiality\n"));
289+
printfPQExpBuffer(&conn->errorMessage,
290+
libpq_gettext("GSSAPI did not provide confidentiality\n"));
291291
ret = -1;
292292
goto cleanup;
293293
}
@@ -328,8 +328,8 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
328328
}
329329
else if (conf == 0)
330330
{
331-
printfPQExpBuffer(&conn->errorMessage, libpq_gettext(
332-
"GSSAPI did not provide confidentiality\n"));
331+
printfPQExpBuffer(&conn->errorMessage,
332+
libpq_gettext("GSSAPI did not provide confidentiality\n"));
333333
ret = -1;
334334
goto cleanup;
335335
}
@@ -476,7 +476,7 @@ pqsecure_open_gss(PGconn *conn)
476476

477477
PqGSSRecvLength += ret;
478478

479-
printfPQExpBuffer(&conn->errorMessage, "%s", PqGSSRecvBuffer + 1);
479+
printfPQExpBuffer(&conn->errorMessage, "%s\n", PqGSSRecvBuffer + 1);
480480

481481
return PGRES_POLLING_FAILED;
482482
}
@@ -490,7 +490,9 @@ pqsecure_open_gss(PGconn *conn)
490490
input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
491491
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
492492
{
493-
printfPQExpBuffer(&conn->errorMessage, libpq_gettext("Over-size GSSAPI packet sent by the server: %ld"), input.length);
493+
printfPQExpBuffer(&conn->errorMessage,
494+
libpq_gettext("oversize GSSAPI packet sent by the server: %zu bytes\n"),
495+
(size_t) input.length);
494496
return PGRES_POLLING_FAILED;
495497
}
496498

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy