summaryrefslogtreecommitdiffstats
path: root/src/util/support
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2006-06-28 05:31:52 +0000
committerKen Raeburn <raeburn@mit.edu>2006-06-28 05:31:52 +0000
commite24eee09ff8de9bcdc7ba8d93519651d1ba3fa62 (patch)
tree954a4384dafbec50b1f2bb1229d90046092ce2ac /src/util/support
parentaef096c6896ed50e4df03361c3b049df91b3f6f0 (diff)
downloadkrb5-e24eee09ff8de9bcdc7ba8d93519651d1ba3fa62.tar.gz
krb5-e24eee09ff8de9bcdc7ba8d93519651d1ba3fa62.tar.xz
krb5-e24eee09ff8de9bcdc7ba8d93519651d1ba3fa62.zip
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
Diffstat (limited to 'src/util/support')
-rw-r--r--src/util/support/errors.c22
1 files changed, 15 insertions, 7 deletions
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