From c59402909451704c36f862fb2968f6c8e717df4c Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 30 Apr 2008 23:46:29 +0000 Subject: [PATCH] (more) After malloc/realloc/calloc/strdup/asprintf failures, use ENOMEM explicitly instead of reading it from errno. This may make static analysis tools less confused about when we return zero vs nonzero values. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20313 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kdc/network.c | 10 +++++----- src/krb524/krb524d.c | 4 ++-- src/lib/gssapi/krb5/gssapi_krb5.c | 4 ++-- src/lib/kadm5/srv/svr_principal.c | 2 +- src/lib/kdb/kdb5.c | 4 ++-- src/lib/krb5/os/changepw.c | 4 ++-- src/lib/krb5/os/init_os_ctx.c | 2 +- src/lib/krb5/os/localaddr.c | 4 ++-- src/lib/krb5/os/sendto_kdc.c | 4 ++-- src/util/support/plugins.c | 24 ++++++++++++------------ 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/kdc/network.c b/src/kdc/network.c index e9dcf8610..82b1c7768 100644 --- a/src/kdc/network.c +++ b/src/kdc/network.c @@ -1,7 +1,7 @@ /* * kdc/network.c * - * Copyright 1990,2000,2007 by the Massachusetts Institute of Technology. + * Copyright 1990,2000,2007,2008 by the Massachusetts Institute of Technology. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -320,14 +320,14 @@ add_fd (struct socksetup *data, int sock, enum kdc_conn_type conntype, } newconn = malloc(sizeof(*newconn)); if (newconn == 0) { - data->retval = errno; - com_err(data->prog, errno, + data->retval = ENOMEM; + com_err(data->prog, ENOMEM, "cannot allocate storage for connection info"); return 0; } if (!ADD(connections, newconn, tmp)) { - data->retval = errno; - com_err(data->prog, data->retval, "cannot save socket info"); + data->retval = ENOMEM; + com_err(data->prog, ENOMEM, "cannot save socket info"); free(newconn); return 0; } diff --git a/src/krb524/krb524d.c b/src/krb524/krb524d.c index c33efa37b..202cda920 100644 --- a/src/krb524/krb524d.c +++ b/src/krb524/krb524d.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2007 by the Massachusetts Institute of Technology. + * Copyright (C) 2002, 2007, 2008 by the Massachusetts Institute of Technology. * All rights reserved. * * Export of this software from the United States of America may @@ -462,7 +462,7 @@ krb5_error_code lookup_service_key(context, p, ktype, kvno, key, kvnop) memcpy(key->contents, entry.key.contents, key->length); else if (key->length) { /* out of memory? */ - ret = errno; + ret = ENOMEM; memset (key, 0, sizeof (*key)); return ret; } diff --git a/src/lib/gssapi/krb5/gssapi_krb5.c b/src/lib/gssapi/krb5/gssapi_krb5.c index 224484f44..95a876371 100644 --- a/src/lib/gssapi/krb5/gssapi_krb5.c +++ b/src/lib/gssapi/krb5/gssapi_krb5.c @@ -203,7 +203,7 @@ kg_get_ccache_name (OM_uint32 *minor_status, const char **out_name) if (kg_ccache_name != NULL) { name = strdup(kg_ccache_name); if (name == NULL) - err = errno; + err = ENOMEM; } else { krb5_context context = NULL; @@ -217,7 +217,7 @@ kg_get_ccache_name (OM_uint32 *minor_status, const char **out_name) if (name) { name = strdup(name); if (name == NULL) - err = errno; + err = ENOMEM; } } if (err && context) diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c index a7636e770..702c175b2 100644 --- a/src/lib/kadm5/srv/svr_principal.c +++ b/src/lib/kadm5/srv/svr_principal.c @@ -1418,7 +1418,7 @@ kadm5_chpass_principal_3(void *server_handle, if (!ret) { pstring = malloc ((princ->length + 1) * sizeof (char)); - if (pstring == NULL) { ret = errno; } + if (pstring == NULL) { ret = ENOMEM; } } if (!ret) { diff --git a/src/lib/kdb/kdb5.c b/src/lib/kdb/kdb5.c index 2b6ed2c64..2a6b4686d 100644 --- a/src/lib/kdb/kdb5.c +++ b/src/lib/kdb/kdb5.c @@ -1,5 +1,5 @@ /* - * Copyright 2006 by the Massachusetts Institute of Technology. + * Copyright 2006, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -354,7 +354,7 @@ kdb_load_library(krb5_context kcontext, char *lib_name, db_library * lib) path = calloc(ndx + db_dl_n_locations, sizeof (char *)); if (path == NULL) { - status = errno; + status = ENOMEM; goto clean_n_exit; } if (ndx) diff --git a/src/lib/krb5/os/changepw.c b/src/lib/krb5/os/changepw.c index 816713dc4..275f61a63 100644 --- a/src/lib/krb5/os/changepw.c +++ b/src/lib/krb5/os/changepw.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/changepw.c * - * Copyright 1990,1999,2001 by the Massachusetts Institute of Technology. + * Copyright 1990,1999,2001,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -139,7 +139,7 @@ static int kpasswd_sendto_msg_callback(struct conn_state *conn, void *callback_c local_kaddr.length = addrs[0]->length; local_kaddr.contents = malloc(addrs[0]->length); if (local_kaddr.contents == NULL && addrs[0]->length != 0) { - code = errno; + code = ENOMEM; krb5_free_addresses(ctx->context, addrs); goto cleanup; } diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index 132816d05..06a5b6bfa 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -309,7 +309,7 @@ add_kdc_config_file(profile_filespec_t **pfiles) memcpy(newfiles + 1, *pfiles, (count-1) * sizeof(*newfiles)); newfiles[0] = strdup(file); if (newfiles[0] == NULL) { - int e = errno; + int e = ENOMEM; free(newfiles); return e; } diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index ea8c9a205..55180808e 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -559,7 +559,7 @@ foreach_localaddr (/*@null@*/ void *data, P.buf_size = P.lifnum.lifn_count * sizeof (struct lifreq) * 2; P.buf = malloc (P.buf_size); if (P.buf == NULL) { - retval = errno; + retval = ENOMEM; goto punt; } @@ -732,7 +732,7 @@ foreach_localaddr (/*@null@*/ void *data, P.buf_size = P.if_num * sizeof (struct if_laddrreq) * 2; P.buf = malloc (P.buf_size); if (P.buf == NULL) { - retval = errno; + retval = ENOMEM; goto punt; } diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index 050aec5f9..cd40cb67b 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/sendto_kdc.c * - * Copyright 1990,1991,2001,2002,2004,2005,2007 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2001,2002,2004,2005,2007,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -1044,7 +1044,7 @@ service_tcp_fd (struct conn_state *conn, struct select_state *selstate, conn->x.in.buf); if (conn->x.in.buf == 0) { /* allocation failure */ - e = errno; + e = ENOMEM; goto kill_conn; } } diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c index 90e16f388..3f71f43a5 100644 --- a/src/util/support/plugins.c +++ b/src/util/support/plugins.c @@ -1,7 +1,7 @@ /* * util/support/plugins.c * - * Copyright 2006 by the Massachusetts Institute of Technology. + * Copyright 2006, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -95,7 +95,7 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct if (!err) { htmp = calloc (1, sizeof (*htmp)); /* calloc initializes ptrs to NULL */ - if (htmp == NULL) { err = errno; } + if (htmp == NULL) { err = ENOMEM; } } #if USE_DLOPEN @@ -303,7 +303,7 @@ krb5int_plugin_file_handle_array_init (struct plugin_file_handle ***harray) long err = 0; *harray = calloc (1, sizeof (**harray)); /* calloc initializes to NULL */ - if (*harray == NULL) { err = errno; } + if (*harray == NULL) { err = ENOMEM; } return err; } @@ -318,7 +318,7 @@ krb5int_plugin_file_handle_array_add (struct plugin_file_handle ***harray, int * newharray = realloc (*harray, ((newcount + 1) * sizeof (**harray))); /* +1 for NULL */ if (newharray == NULL) { - err = errno; + err = ENOMEM; } else { newharray[newcount - 1] = p; newharray[newcount] = NULL; @@ -380,7 +380,7 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames) for (i = 0; filebases[i]; i++) { bases_count++; } for (i = 0; fileexts[i]; i++) { exts_count++; } tempnames = calloc ((bases_count * exts_count)+1, sizeof (char *)); - if (!tempnames) { err = errno; } + if (!tempnames) { err = ENOMEM; } } if (!err) { @@ -390,7 +390,7 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames) if (asprintf(&tempnames[(i*exts_count)+j], "%s%s", filebases[i], fileexts[j]) < 0) { tempnames[(i*exts_count)+j] = NULL; - err = errno; + err = ENOMEM; } } } @@ -444,7 +444,7 @@ krb5int_open_plugin_dirs (const char * const *dirnames, if (!err) { if (asprintf(&filepath, "%s/%s", dirnames[i], filenames[j]) < 0) { filepath = NULL; - err = errno; + err = ENOMEM; } } @@ -478,7 +478,7 @@ krb5int_open_plugin_dirs (const char * const *dirnames, int len = NAMELEN (d); if (asprintf(&filepath, "%s/%*s", dirnames[i], len, d->d_name) < 0) { filepath = NULL; - err = errno; + err = ENOMEM; } } @@ -553,7 +553,7 @@ krb5int_get_plugin_dir_data (struct plugin_dir_handle *dirhandle, if (!err) { p = calloc (1, sizeof (*p)); /* calloc initializes to NULL */ - if (p == NULL) { err = errno; } + if (p == NULL) { err = ENOMEM; } } if (!err && (dirhandle != NULL) && (dirhandle->files != NULL)) { @@ -568,7 +568,7 @@ krb5int_get_plugin_dir_data (struct plugin_dir_handle *dirhandle, count++; newp = realloc (p, ((count + 1) * sizeof (*p))); /* +1 for NULL */ if (newp == NULL) { - err = errno; + err = ENOMEM; } else { p = newp; p[count - 1] = sym; @@ -612,7 +612,7 @@ krb5int_get_plugin_dir_func (struct plugin_dir_handle *dirhandle, if (!err) { p = calloc (1, sizeof (*p)); /* calloc initializes to NULL */ - if (p == NULL) { err = errno; } + if (p == NULL) { err = ENOMEM; } } if (!err && (dirhandle != NULL) && (dirhandle->files != NULL)) { @@ -627,7 +627,7 @@ krb5int_get_plugin_dir_func (struct plugin_dir_handle *dirhandle, count++; newp = realloc (p, ((count + 1) * sizeof (*p))); /* +1 for NULL */ if (newp == NULL) { - err = errno; + err = ENOMEM; } else { p = newp; p[count - 1] = sym; -- 2.26.2