]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix pg_GSS_error to use conn->errorMessage more sanely, ie, actually
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 31 Jan 2008 18:58:30 +0000 (18:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 31 Jan 2008 18:58:30 +0000 (18:58 +0000)
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

index 07018fdda1e100eec36da4d2a6f0ff0a380e10a0..f0d7948712921d80ce568ef601cd35720b15a4ab 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.136 2008/01/01 19:46:00 momjian Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.137 2008/01/31 18:58:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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);
 }
 
 /*