From 7d48b8368db9bdc27dfb285a1faa1a1336a8fa2b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 31 Jan 2008 18:58:30 +0000 Subject: [PATCH] Fix pg_GSS_error to use conn->errorMessage more sanely, ie, actually work with the PQExpBuffer code instead of fighting it. This avoids an unnecessary limit on message length and fixes the latent bug that errorMessage.len wasn't getting set. --- src/interfaces/libpq/fe-auth.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 0ce50cd6de..490ca1bb3b 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -340,14 +340,12 @@ static GSS_DLLIMP gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVI #endif /* - * Fetch all errors of a specific type that fit into a buffer - * and append them. + * Fetch all errors of a specific type and append to "str". */ static void -pg_GSS_error_int(char *mprefix, char *msg, int msglen, +pg_GSS_error_int(PQExpBuffer str, const char *mprefix, OM_uint32 stat, int type) { - int curlen = 0; OM_uint32 lmaj_s, lmin_s; gss_buffer_desc lmsg; @@ -357,36 +355,25 @@ pg_GSS_error_int(char *mprefix, char *msg, int msglen, { lmaj_s = gss_display_status(&lmin_s, stat, type, GSS_C_NO_OID, &msg_ctx, &lmsg); - - if (curlen < msglen) - { - snprintf(msg + curlen, msglen - curlen, "%s: %s\n", - mprefix, (char *) lmsg.value); - curlen += lmsg.length; - } + appendPQExpBuffer(str, "%s: %s\n", mprefix, (char *) lmsg.value); gss_release_buffer(&lmin_s, &lmsg); } while (msg_ctx); } /* - * GSSAPI errors contains two parts. Put as much as possible of - * both parts into the string. + * GSSAPI errors contain two parts; put both into conn->errorMessage. */ static void -pg_GSS_error(char *mprefix, PGconn *conn, +pg_GSS_error(const char *mprefix, PGconn *conn, OM_uint32 maj_stat, OM_uint32 min_stat) { - int mlen; + resetPQExpBuffer(&conn->errorMessage); /* Fetch major error codes */ - pg_GSS_error_int(mprefix, conn->errorMessage.data, - conn->errorMessage.maxlen, maj_stat, GSS_C_GSS_CODE); - mlen = strlen(conn->errorMessage.data); - - /* If there is room left, try to add the minor codes as well */ - if (mlen < conn->errorMessage.maxlen - 1) - pg_GSS_error_int(mprefix, conn->errorMessage.data + mlen, - conn->errorMessage.maxlen - mlen, min_stat, GSS_C_MECH_CODE); + pg_GSS_error_int(&conn->errorMessage, mprefix, maj_stat, GSS_C_GSS_CODE); + + /* Add the minor codes as well */ + pg_GSS_error_int(&conn->errorMessage, mprefix, min_stat, GSS_C_MECH_CODE); } /* -- 2.39.5