From: Ken Raeburn Date: Wed, 28 Jun 2006 05:31:52 +0000 (+0000) Subject: allow multiple calls to krb5_get_error_message to retrieve message X-Git-Tag: krb5-1.6-alpha1~255 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e24eee09ff8de9bcdc7ba8d93519651d1ba3fa62;p=krb5.git allow multiple calls to krb5_get_error_message to retrieve message (krb5int_get_error): Don't discard old message if the error codes don't match. Try a little harder not to keep messages in the scratch buffer. Return a copy of the message, or "out of memory" in the scratch buffer. (krb5int_vset_error): Try a little harder not to keep messages in the scratch buffer. ticket: new target_version: 1.5 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18246 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/support/errors.c b/src/util/support/errors.c index 67ddf625c..7c93753d4 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -48,6 +48,8 @@ void krb5int_vset_error (struct errinfo *ep, long code, const char *fmt, va_list args) { + char *p; + if (ep->msg && ep->msg != ep->scratch_buf) { free (ep->msg); ep->msg = NULL; @@ -63,18 +65,20 @@ krb5int_vset_error (struct errinfo *ep, long code, } #endif vsnprintf(ep->scratch_buf, sizeof(ep->scratch_buf), fmt, args); - ep->msg = ep->scratch_buf; + p = strdup(ep->scratch_buf); + ep->msg = p ? p : ep->scratch_buf; } char * krb5int_get_error (struct errinfo *ep, long code) { char *r, *r2; - if (code != ep->code) - krb5int_clear_error (ep); - if (ep->msg) { - r = ep->msg; - ep->msg = NULL; + if (code == ep->code && ep->msg) { + r = strdup(ep->msg); + if (r == NULL) { + strcpy(ep->scratch_buf, _("Out of memory")); + r = ep->scratch_buf; + } return r; } if (initialize() != 0) { @@ -88,8 +92,12 @@ krb5int_get_error (struct errinfo *ep, long code) if (fptr == NULL) { unlock(); #ifdef HAVE_STRERROR_R - if (strerror_r (code, ep->scratch_buf, sizeof(ep->scratch_buf)) == 0) + if (strerror_r (code, ep->scratch_buf, sizeof(ep->scratch_buf)) == 0) { + char *p = strdup(ep->scratch_buf); + if (p) + return p; return ep->scratch_buf; + } /* If strerror_r didn't work with the 1K buffer, we can try a really big one. This seems kind of gratuitous though. */ #define BIG_ERR_BUFSIZ 8192