catch error from as.*printf
This commit is contained in:
@@ -1028,11 +1028,11 @@ acc_get_default_name(krb5_context context, char **str)
|
|||||||
return translate_cc_error(context, error);
|
return translate_cc_error(context, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf(str, "API:%s", name->data);
|
error = asprintf(str, "API:%s", name->data);
|
||||||
(*name->func->release)(name);
|
(*name->func->release)(name);
|
||||||
(*cc->func->release)(cc);
|
(*cc->func->release)(cc);
|
||||||
|
|
||||||
if (*str == NULL) {
|
if (error < 0 || *str == NULL) {
|
||||||
krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
|
krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
@@ -447,8 +447,9 @@ krb5_config_parse_file_multi (krb5_context context,
|
|||||||
fname = newfname;
|
fname = newfname;
|
||||||
}
|
}
|
||||||
#else /* KRB5_USE_PATH_TOKENS */
|
#else /* KRB5_USE_PATH_TOKENS */
|
||||||
asprintf(&newfname, "%%{USERCONFIG}%s", &fname[1]);
|
if (asprintf(&newfname, "%%{USERCONFIG}%s", &fname[1]) < 0 ||
|
||||||
if (newfname == NULL) {
|
newfname == NULL)
|
||||||
|
{
|
||||||
krb5_set_error_message(context, ENOMEM,
|
krb5_set_error_message(context, ENOMEM,
|
||||||
N_("malloc: out of memory", ""));
|
N_("malloc: out of memory", ""));
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
@@ -96,11 +96,14 @@ krb5_vset_error_message (krb5_context context, krb5_error_code ret,
|
|||||||
const char *fmt, va_list args)
|
const char *fmt, va_list args)
|
||||||
__attribute__ ((format (printf, 3, 0)))
|
__attribute__ ((format (printf, 3, 0)))
|
||||||
{
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
krb5_clear_error_message(context);
|
krb5_clear_error_message(context);
|
||||||
HEIMDAL_MUTEX_lock(context->mutex);
|
HEIMDAL_MUTEX_lock(context->mutex);
|
||||||
context->error_code = ret;
|
context->error_code = ret;
|
||||||
vasprintf(&context->error_string, fmt, args);
|
r = vasprintf(&context->error_string, fmt, args);
|
||||||
|
if (r)
|
||||||
|
context->error_string = NULL;
|
||||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,19 +147,22 @@ krb5_vprepend_error_message(krb5_context context, krb5_error_code ret,
|
|||||||
const char *fmt, va_list args)
|
const char *fmt, va_list args)
|
||||||
__attribute__ ((format (printf, 3, 0)))
|
__attribute__ ((format (printf, 3, 0)))
|
||||||
{
|
{
|
||||||
char *str, *str2;
|
char *str = NULL, *str2 = NULL;
|
||||||
HEIMDAL_MUTEX_lock(context->mutex);
|
HEIMDAL_MUTEX_lock(context->mutex);
|
||||||
if (context->error_code != ret) {
|
if (context->error_code != ret) {
|
||||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vasprintf(&str, fmt, args);
|
if (vasprintf(&str, fmt, args) < 0 || str == NULL) {
|
||||||
|
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (context->error_string) {
|
if (context->error_string) {
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
e = asprintf(&str2, "%s: %s", str, context->error_string);
|
e = asprintf(&str2, "%s: %s", str, context->error_string);
|
||||||
free(context->error_string);
|
free(context->error_string);
|
||||||
if (e < 0)
|
if (e < 0 || str2 == NULL)
|
||||||
context->error_string = NULL;
|
context->error_string = NULL;
|
||||||
else
|
else
|
||||||
context->error_string = str2;
|
context->error_string = str2;
|
||||||
|
@@ -234,11 +234,12 @@ report_expiration (krb5_context context,
|
|||||||
const char *str,
|
const char *str,
|
||||||
time_t now)
|
time_t now)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p = NULL;
|
||||||
|
|
||||||
asprintf (&p, "%s%s", str, ctime(&now));
|
if (asprintf(&p, "%s%s", str, ctime(&now)) < 0 || p == NULL)
|
||||||
(*prompter) (context, data, NULL, p, 0, NULL);
|
return;
|
||||||
free (p);
|
(*prompter)(context, data, NULL, p, 0, NULL);
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -562,10 +563,14 @@ change_password (krb5_context context,
|
|||||||
&result_string);
|
&result_string);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
asprintf (&p, "%s: %.*s\n",
|
if (asprintf(&p, "%s: %.*s\n",
|
||||||
result_code ? "Error" : "Success",
|
result_code ? "Error" : "Success",
|
||||||
(int)result_string.length,
|
(int)result_string.length,
|
||||||
result_string.length > 0 ? (char*)result_string.data : "");
|
result_string.length > 0 ? (char*)result_string.data : "") < 0)
|
||||||
|
{
|
||||||
|
ret = ENOMEM;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* return the result */
|
/* return the result */
|
||||||
(*prompter) (context, data, NULL, p, 0, NULL);
|
(*prompter) (context, data, NULL, p, 0, NULL);
|
||||||
|
@@ -448,7 +448,7 @@ static krb5_error_code
|
|||||||
fallback_get_hosts(krb5_context context, struct krb5_krbhst_data *kd,
|
fallback_get_hosts(krb5_context context, struct krb5_krbhst_data *kd,
|
||||||
const char *serv_string, int port, int proto)
|
const char *serv_string, int port, int proto)
|
||||||
{
|
{
|
||||||
char *host;
|
char *host = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
@@ -467,12 +467,12 @@ fallback_get_hosts(krb5_context context, struct krb5_krbhst_data *kd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(kd->fallback_count == 0)
|
if(kd->fallback_count == 0)
|
||||||
asprintf(&host, "%s.%s.", serv_string, kd->realm);
|
ret = asprintf(&host, "%s.%s.", serv_string, kd->realm);
|
||||||
else
|
else
|
||||||
asprintf(&host, "%s-%d.%s.",
|
ret = asprintf(&host, "%s-%d.%s.",
|
||||||
serv_string, kd->fallback_count, kd->realm);
|
serv_string, kd->fallback_count, kd->realm);
|
||||||
|
|
||||||
if (host == NULL)
|
if (ret < 0 || host == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
make_hints(&hints, proto);
|
make_hints(&hints, proto);
|
||||||
|
@@ -67,15 +67,16 @@ static krb5_mcache *
|
|||||||
mcc_alloc(const char *name)
|
mcc_alloc(const char *name)
|
||||||
{
|
{
|
||||||
krb5_mcache *m, *m_c;
|
krb5_mcache *m, *m_c;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
ALLOC(m, 1);
|
ALLOC(m, 1);
|
||||||
if(m == NULL)
|
if(m == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if(name == NULL)
|
if(name == NULL)
|
||||||
asprintf(&m->name, "%p", m);
|
ret = asprintf(&m->name, "%p", m);
|
||||||
else
|
else
|
||||||
m->name = strdup(name);
|
m->name = strdup(name);
|
||||||
if(m->name == NULL) {
|
if(ret < 0 || m->name == NULL) {
|
||||||
free(m);
|
free(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -226,17 +226,18 @@ load_plugins(krb5_context context)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
path = NULL;
|
path = NULL;
|
||||||
|
ret = 0;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
{ /* support loading bundles on MacOS */
|
{ /* support loading bundles on MacOS */
|
||||||
size_t len = strlen(n);
|
size_t len = strlen(n);
|
||||||
if (len > 7 && strcmp(&n[len - 7], ".bundle") == 0)
|
if (len > 7 && strcmp(&n[len - 7], ".bundle") == 0)
|
||||||
asprintf(&path, "%s/%s/Contents/MacOS/%.*s", *di, n, (int)(len - 7), n);
|
ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", *di, n, (int)(len - 7), n);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (path == NULL)
|
if (ret < 0 || path == NULL)
|
||||||
asprintf(&path, "%s/%s", *di, n);
|
ret = asprintf(&path, "%s/%s", *di, n);
|
||||||
|
|
||||||
if (path == NULL) {
|
if (ret < 0 || path == NULL) {
|
||||||
ret = ENOMEM;
|
ret = ENOMEM;
|
||||||
krb5_set_error_message(context, ret, "malloc: out of memory");
|
krb5_set_error_message(context, ret, "malloc: out of memory");
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -308,12 +308,12 @@ krb5_get_server_rcache(krb5_context context,
|
|||||||
}
|
}
|
||||||
strvisx(tmp, piece->data, piece->length, VIS_WHITE | VIS_OCTAL);
|
strvisx(tmp, piece->data, piece->length, VIS_WHITE | VIS_OCTAL);
|
||||||
#ifdef HAVE_GETEUID
|
#ifdef HAVE_GETEUID
|
||||||
asprintf(&name, "FILE:rc_%s_%u", tmp, (unsigned)geteuid());
|
ret = asprintf(&name, "FILE:rc_%s_%u", tmp, (unsigned)geteuid());
|
||||||
#else
|
#else
|
||||||
asprintf(&name, "FILE:rc_%s", tmp);
|
ret = asprintf(&name, "FILE:rc_%s", tmp);
|
||||||
#endif
|
#endif
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if(name == NULL) {
|
if(ret < 0 || name == NULL) {
|
||||||
krb5_set_error_message(context, ENOMEM,
|
krb5_set_error_message(context, ENOMEM,
|
||||||
N_("malloc: out of memory", ""));
|
N_("malloc: out of memory", ""));
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
@@ -296,6 +296,7 @@ out:
|
|||||||
static krb5_scache *
|
static krb5_scache *
|
||||||
scc_alloc(krb5_context context, const char *name)
|
scc_alloc(krb5_context context, const char *name)
|
||||||
{
|
{
|
||||||
|
krb5_error_code ret;
|
||||||
krb5_scache *s;
|
krb5_scache *s;
|
||||||
|
|
||||||
ALLOC(s, 1);
|
ALLOC(s, 1);
|
||||||
@@ -319,14 +320,15 @@ scc_alloc(krb5_context context, const char *name)
|
|||||||
if (file) {
|
if (file) {
|
||||||
*file++ = '\0';
|
*file++ = '\0';
|
||||||
s->file = strdup(file);
|
s->file = strdup(file);
|
||||||
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
_krb5_expand_default_cc_name(context, KRB5_SCACHE_DB, &s->file);
|
ret = _krb5_expand_default_cc_name(context, KRB5_SCACHE_DB, &s->file);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_krb5_expand_default_cc_name(context, KRB5_SCACHE_DB, &s->file);
|
_krb5_expand_default_cc_name(context, KRB5_SCACHE_DB, &s->file);
|
||||||
asprintf(&s->name, "unique-%p", s);
|
ret = asprintf(&s->name, "unique-%p", s);
|
||||||
}
|
}
|
||||||
if (s->file == NULL || s->name == NULL) {
|
if (ret < 0 || s->file == NULL || s->name == NULL) {
|
||||||
scc_free(s);
|
scc_free(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user