diff options
author | Tom Lane | 2013-10-22 22:42:13 +0000 |
---|---|---|
committer | Tom Lane | 2013-10-22 22:42:13 +0000 |
commit | 09a89cb5fc29b47c26d151e82293fd3bef592b7b (patch) | |
tree | 0ac288fac9c8b34730cca74bd90afa06752988ce /src/interfaces/libpq/fe-auth.c | |
parent | 586a8fc75bf266214d635cdcf527176b80f808ea (diff) |
Get rid of use of asprintf() in favor of a more portable implementation.
asprintf(), aside from not being particularly portable, has a fundamentally
badly-designed API; the psprintf() function that was added in passing in
the previous patch has a much better API choice. Moreover, the NetBSD
implementation that was borrowed for the previous patch doesn't work with
non-C99-compliant vsnprintf, which is something we still have to cope with
on some platforms; and it depends on va_copy which isn't all that portable
either. Get rid of that code in favor of an implementation similar to what
we've used for many years in stringinfo.c. Also, move it into libpgcommon
since it's not really libpgport material.
I think this patch will be enough to turn the buildfarm green again, but
there's still cosmetic work left to do, namely get rid of pg_asprintf()
in favor of using psprintf(). That will come in a followon patch.
Diffstat (limited to 'src/interfaces/libpq/fe-auth.c')
-rw-r--r-- | src/interfaces/libpq/fe-auth.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index dfc9cfb1fbe..975f7958d11 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -420,6 +420,7 @@ pg_GSS_startup(PGconn *conn) { OM_uint32 maj_stat, min_stat; + int maxlen; gss_buffer_desc temp_gbuf; if (!(conn->pghost && conn->pghost[0] != '\0')) @@ -440,14 +441,16 @@ pg_GSS_startup(PGconn *conn) * Import service principal name so the proper ticket can be acquired by * the GSSAPI system. */ - if (asprintf((char **)&temp_gbuf.value, "%s@%s", - conn->krbsrvname, conn->pghost) < 0) + maxlen = NI_MAXHOST + strlen(conn->krbsrvname) + 2; + temp_gbuf.value = (char *) malloc(maxlen); + if (!temp_gbuf.value) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("out of memory")); + libpq_gettext("out of memory\n")); return STATUS_ERROR; } - + snprintf(temp_gbuf.value, maxlen, "%s@%s", + conn->krbsrvname, conn->pghost); temp_gbuf.length = strlen(temp_gbuf.value); maj_stat = gss_import_name(&min_stat, &temp_gbuf, @@ -659,11 +662,13 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate) libpq_gettext("host name must be specified\n")); return STATUS_ERROR; } - if (asprintf(&conn->sspitarget, "%s/%s", conn->krbsrvname, conn->pghost) < 0) + conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(conn->pghost) + 2); + if (!conn->sspitarget) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("out of memory\n")); return STATUS_ERROR; } + sprintf(conn->sspitarget, "%s/%s", conn->krbsrvname, conn->pghost); /* * Indicate that we're in SSPI authentication mode to make sure that |