From ec5b9670de4c7af9ebaecfbd305857ee030460c0 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 30 Apr 2008 23:18:21 +0000 Subject: [PATCH] After malloc/realloc/calloc failures, return 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@20312 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/compat_recv.c | 4 ++-- src/clients/ksu/ccache.c | 12 ++++++------ src/clients/ksu/heuristic.c | 8 ++++---- src/clients/ksu/main.c | 2 +- src/lib/crypto/des/string2key.c | 4 ++-- src/lib/crypto/dk/dk_encrypt.c | 2 +- src/lib/crypto/pbkdf2.c | 6 +++--- src/lib/kadm5/alt_prof.c | 4 ++-- src/lib/kadm5/srv/server_dict.c | 4 ++-- src/lib/krb5/ccache/cc_memory.c | 4 ++-- src/lib/krb5/os/hostaddr.c | 4 ++-- src/lib/krb5/os/init_os_ctx.c | 4 ++-- src/lib/krb5/os/localaddr.c | 6 +++--- src/lib/krb5/os/locate_kdc.c | 4 ++-- src/util/et/error_message.c | 4 ++-- src/util/et/init_et.c | 4 ++-- src/util/profile/prof_file.c | 2 +- src/util/profile/prof_init.c | 2 +- src/util/profile/profile.swg | 8 ++++---- src/util/profile/profile_tcl.c | 6 +++--- src/util/support/threads.c | 8 ++++---- 21 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/appl/bsd/compat_recv.c b/src/appl/bsd/compat_recv.c index c76c4142c..1e54941e1 100644 --- a/src/appl/bsd/compat_recv.c +++ b/src/appl/bsd/compat_recv.c @@ -1,7 +1,7 @@ /* * lib/krb5/krb/compat_recv.c * - * Copyright 1993 by the Massachusetts Institute of Technology. + * Copyright 1993, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -276,7 +276,7 @@ krb5_compat_recvauth_version(context, auth_context, version->data = malloc (KRB_SENDAUTH_VLEN + 1); version->data[KRB_SENDAUTH_VLEN] = 0; if (version->data == 0) - return errno; + return ENOMEM; retval = krb_v4_recvauth(v4_options, fd, v4_ticket, v4_service, v4_instance, v4_faddr, v4_laddr, *v4_kdata, v4_filename, diff --git a/src/clients/ksu/ccache.c b/src/clients/ksu/ccache.c index 5e9c5ec51..ec8f2af0e 100644 --- a/src/clients/ksu/ccache.c +++ b/src/clients/ksu/ccache.c @@ -226,7 +226,7 @@ int count = 0; int chunk_count = 1; if ( ! ( temp_creds = (krb5_creds **) malloc( CHUNK * sizeof(krb5_creds *)))){ - return errno; + return ENOMEM; } @@ -264,7 +264,7 @@ int chunk_count = 1; chunk_count ++; if (!(temp_creds = (krb5_creds **) realloc(temp_creds, chunk_count * CHUNK * sizeof(krb5_creds *)))){ - return errno; + return ENOMEM; } } } @@ -415,9 +415,9 @@ krb5_get_login_princ(luser, princ_list) /* check each line */ - if( !(linebuf = (char *) calloc (BUFSIZ, sizeof(char)))) return errno; + if( !(linebuf = (char *) calloc (BUFSIZ, sizeof(char)))) return ENOMEM; - if (!(buf_out = (char **) malloc( CHUNK * sizeof(char *)))) return errno; + if (!(buf_out = (char **) malloc( CHUNK * sizeof(char *)))) return ENOMEM; while ( fgets(linebuf, BUFSIZ, fp) != NULL) { /* null-terminate the input string */ @@ -434,7 +434,7 @@ krb5_get_login_princ(luser, princ_list) chunk_count ++; if (!(buf_out = (char **) realloc(buf_out, chunk_count * CHUNK * sizeof(char *)))){ - return errno; + return ENOMEM; } } @@ -442,7 +442,7 @@ krb5_get_login_princ(luser, princ_list) if (!newline) while (((gobble = getc(fp)) != EOF) && gobble != '\n'); - if( !(linebuf = (char *) calloc (BUFSIZ, sizeof(char)))) return errno; + if( !(linebuf = (char *) calloc (BUFSIZ, sizeof(char)))) return ENOMEM; } buf_out[count] = NULL; diff --git a/src/clients/ksu/heuristic.c b/src/clients/ksu/heuristic.c index 2eeadd454..80482bebb 100644 --- a/src/clients/ksu/heuristic.c +++ b/src/clients/ksu/heuristic.c @@ -50,7 +50,7 @@ krb5_error_code get_all_princ_from_file (fp, plist) int count = 0, chunk_count = 1; if (!(temp_list = (char **) malloc( CHUNK * sizeof(char *)))) - return errno; + return ENOMEM; retval = get_line(fp, &line); if (retval) @@ -68,7 +68,7 @@ krb5_error_code get_all_princ_from_file (fp, plist) chunk_count ++; if (!(temp_list = (char **) realloc(temp_list, chunk_count * CHUNK * sizeof(char *)))){ - return errno; + return ENOMEM; } } @@ -114,7 +114,7 @@ krb5_error_code list_union(list1, list2, combined_list) while (list2[c2]) c2++; if (!(tlist = (char **) calloc( c1 + c2 + 1, sizeof ( char *)))) - return errno; + return ENOMEM; i = 0; while(list1[i]) { @@ -176,7 +176,7 @@ filter(fp, cmd, k5users_list, k5users_filt_list) } if (! (temp_filt_list = (char **) calloc(found_count +1, sizeof (char*)))) - return errno; + return ENOMEM; for(j= 0, k=0; j < i; j++ ) { if (k5users_list[j]){ diff --git a/src/clients/ksu/main.c b/src/clients/ksu/main.c index f3d844069..3329bd78a 100644 --- a/src/clients/ksu/main.c +++ b/src/clients/ksu/main.c @@ -931,7 +931,7 @@ get_params(optindex, pargc, pargv, params) int size = pargc - *optindex + 2; if ((ret_params = (char **) calloc(size, sizeof (char *)))== NULL ){ - return errno; + return ENOMEM; } for (i = *optindex, j=1; i < pargc; i++,j++){ diff --git a/src/lib/crypto/des/string2key.c b/src/lib/crypto/des/string2key.c index 4fe9e4799..016ae3e20 100644 --- a/src/lib/crypto/des/string2key.c +++ b/src/lib/crypto/des/string2key.c @@ -1,7 +1,7 @@ /* * lib/crypto/des/des_s2k.c * - * Copyright 2004 by the Massachusetts Institute of Technology. + * Copyright 2004, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -84,7 +84,7 @@ mit_des_string_to_key_int (krb5_keyblock *key, a byte array, not a string. */ copy = malloc(copylen); if (copy == NULL) - return errno; + return ENOMEM; memcpy(copy, pw->data, pw->length); if (salt) memcpy(copy + pw->length, salt->data, salt->length); diff --git a/src/lib/crypto/dk/dk_encrypt.c b/src/lib/crypto/dk/dk_encrypt.c index 5b2d3e793..750f43ffe 100644 --- a/src/lib/crypto/dk/dk_encrypt.c +++ b/src/lib/crypto/dk/dk_encrypt.c @@ -205,7 +205,7 @@ trunc_hmac (const struct krb5_hash_provider *hash, tmp.length = hashsize; tmp.data = malloc(hashsize); if (tmp.data == NULL) - return errno; + return ENOMEM; ret = krb5_hmac(hash, ki, num, input, &tmp); if (ret == 0) memcpy(output->data, tmp.data, output->length); diff --git a/src/lib/crypto/pbkdf2.c b/src/lib/crypto/pbkdf2.c index ff446dbde..a6cce1cd0 100644 --- a/src/lib/crypto/pbkdf2.c +++ b/src/lib/crypto/pbkdf2.c @@ -1,7 +1,7 @@ /* * lib/crypto/pbkdf2.c * - * Copyright 2002 by the Massachusetts Institute of Technology. + * Copyright 2002, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -171,11 +171,11 @@ krb5int_pbkdf2 (krb5_error_code (*prf)(krb5_keyblock *, krb5_data *, utmp1 = /*output + dklen; */ malloc(hlen); if (utmp1 == NULL) - return errno; + return ENOMEM; utmp2 = /*utmp1 + hlen; */ malloc(salt->length + 4 + hlen); if (utmp2 == NULL) { free(utmp1); - return errno; + return ENOMEM; } /* Step 3. */ diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index 6802090d5..5724c1403 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -1,7 +1,7 @@ /* * lib/kadm/alt_prof.c * - * Copyright 1995,2001 by the Massachusetts Institute of Technology. + * Copyright 1995,2001,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -91,7 +91,7 @@ krb5_aprof_init(fname, envname, acontextp) profile_path = malloc(2 + krb5_config_len + kdc_config_len); if (profile_path == NULL) { krb5_free_config_files(filenames); - return errno; + return ENOMEM; } if (kdc_config_len) strcpy(profile_path, kdc_config); diff --git a/src/lib/kadm5/srv/server_dict.c b/src/lib/kadm5/srv/server_dict.c index 4f41b0d41..ece7831c9 100644 --- a/src/lib/kadm5/srv/server_dict.c +++ b/src/lib/kadm5/srv/server_dict.c @@ -108,7 +108,7 @@ int init_dict(kadm5_config_params *params) return errno; } if ((word_block = (char *) malloc(sb.st_size + 1)) == NULL) - return errno; + return ENOMEM; if (read(fd, word_block, sb.st_size) != sb.st_size) return errno; (void) close(fd); @@ -123,7 +123,7 @@ int init_dict(kadm5_config_params *params) word_count++; } if ((word_list = (char **) malloc(word_count * sizeof(char *))) == NULL) - return errno; + return ENOMEM; p = word_block; for (i = 0; i < word_count; i++) { word_list[i] = p; diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c index 173d0039d..d5c0493ba 100644 --- a/src/lib/krb5/ccache/cc_memory.c +++ b/src/lib/krb5/ccache/cc_memory.c @@ -1,7 +1,7 @@ /* * lib/krb5/ccache/cc_memory.c * - * Copyright 1990,1991,2000,2004 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2000,2004,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -614,7 +614,7 @@ krb5_mcc_store(krb5_context ctx, krb5_ccache id, krb5_creds *creds) new_node = malloc(sizeof(krb5_mcc_link)); if (new_node == NULL) - return errno; + return ENOMEM; err = krb5_copy_creds(ctx, creds, &new_node->creds); if (err) { free(new_node); diff --git a/src/lib/krb5/os/hostaddr.c b/src/lib/krb5/os/hostaddr.c index 76eb1273d..eaef09858 100644 --- a/src/lib/krb5/os/hostaddr.c +++ b/src/lib/krb5/os/hostaddr.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/hostaddr.c * - * Copyright 1990,1991 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -73,7 +73,7 @@ krb5_os_hostaddr(krb5_context context, const char *name, krb5_address ***ret_add addrs = malloc ((i+1) * sizeof(*addrs)); if (!addrs) - return errno; + return ENOMEM; for (j = 0; j < i + 1; j++) addrs[j] = 0; diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index 16ff0435f..132816d05 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/init_ctx.c * - * Copyright 1994, 2007 by the Massachusetts Institute of Technology. + * Copyright 1994, 2007, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -305,7 +305,7 @@ add_kdc_config_file(profile_filespec_t **pfiles) count += 2; newfiles = malloc(count * sizeof(*newfiles)); if (newfiles == NULL) - return errno; + return ENOMEM; memcpy(newfiles + 1, *pfiles, (count-1) * sizeof(*newfiles)); newfiles[0] = strdup(file); if (newfiles[0] == NULL) { diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index e139ca4d3..ea8c9a205 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/localaddr.c * - * Copyright 1990,1991,2000,2001,2002,2004,2007 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2000,2001,2002,2004,2007,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -873,7 +873,7 @@ get_ifreq_array(char **bufp, size_t *np, int s) current_buf_size = est_ifreq_size * est_if_count + SLOP; buf = malloc (current_buf_size); if (buf == NULL) - return errno; + return ENOMEM; ask_again: size = current_buf_size; @@ -905,7 +905,7 @@ ask_again: new_size = est_ifreq_size * est_if_count + SLOP; buf = grow_or_free (buf, new_size); if (buf == 0) - return errno; + return ENOMEM; current_buf_size = new_size; goto ask_again; } diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c index 7605328ae..aedb14a88 100644 --- a/src/lib/krb5/os/locate_kdc.c +++ b/src/lib/krb5/os/locate_kdc.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/locate_kdc.c * - * Copyright 1990,2000,2001,2002,2003,2004,2006 Massachusetts Institute of Technology. + * Copyright 1990,2000,2001,2002,2003,2004,2006,2008 Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -110,7 +110,7 @@ krb5int_grow_addrlist (struct addrlist *lp, int nmore) newaddrs = realloc (lp->addrs, newsize); if (newaddrs == NULL) - return errno; + return ENOMEM; lp->addrs = newaddrs; for (i = lp->space; i < newspace; i++) { lp->addrs[i].ai = NULL; diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index 6a3a6ccaa..7bd989485 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -1,5 +1,5 @@ /* - * Copyright 1997,2000,2001,2004 by Massachusetts Institute of Technology + * Copyright 1997,2000,2001,2004,2008 by Massachusetts Institute of Technology * * Copyright 1987, 1988 by MIT Student Information Processing Board * @@ -294,7 +294,7 @@ add_error_table(/*@dependent@*/ const struct error_table * et) del = (struct dynamic_et_list *)malloc(sizeof(struct dynamic_et_list)); if (del == NULL) - return errno; + return ENOMEM; del->table = et; diff --git a/src/util/et/init_et.c b/src/util/et/init_et.c index b0a406403..e397a2706 100644 --- a/src/util/et/init_et.c +++ b/src/util/et/init_et.c @@ -1,5 +1,5 @@ /* - * Copyright 1997 by Massachusetts Institute of Technology + * Copyright 1997, 2008 by Massachusetts Institute of Technology * * Copyright 1986, 1987, 1988 by MIT Student Information Processing Board * @@ -47,7 +47,7 @@ int init_error_table(msgs, base, count) new_et = (struct foobar *) malloc(sizeof(struct foobar)); if (!new_et) - return errno; /* oops */ + return ENOMEM; /* oops */ new_et->etl.table = &new_et->et; new_et->et.msgs = msgs; new_et->et.base = base; diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 44d63a8ba..c6f15fee5 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -228,7 +228,7 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, expanded_filename = malloc(len); if (expanded_filename == 0) { free(prf); - return errno; + return ENOMEM; } if (home_env) { strcpy(expanded_filename, home_env); diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c index e5c6f9c8c..9a5659a8c 100644 --- a/src/util/profile/prof_init.c +++ b/src/util/profile/prof_init.c @@ -90,7 +90,7 @@ profile_copy(profile_t old_profile, profile_t *new_profile) COUNT_LINKED_LIST (size, prf_file_t, old_profile->first_file, next); files = malloc ((size+1) * sizeof(*files)); if (files == NULL) - return errno; + return ENOMEM; for (i = 0, file = old_profile->first_file; i < size; i++, file = file->next) files[i] = file->data->filespec; files[size] = NULL; diff --git a/src/util/profile/profile.swg b/src/util/profile/profile.swg index 2e75bb4c6..074a97b9e 100644 --- a/src/util/profile/profile.swg +++ b/src/util/profile/profile.swg @@ -1,6 +1,6 @@ %{ /* - * Copyright 2004 by the Massachusetts Institute of Technology. + * Copyright 2004, 2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -204,7 +204,7 @@ static errcode_t iter_create(profile_t p, const char **nullterm, it = malloc(sizeof(*it)); if (it == NULL) - return errno; + return ENOMEM; { /* Memory leak! @@ -218,11 +218,11 @@ static errcode_t iter_create(profile_t p, const char **nullterm, for (count = 0; nullterm[count]; count++) ; args = calloc(count+1, sizeof(char *)); if (args == NULL) - return errno; + return ENOMEM; for (j = 0; j < count; j++) { args[j] = strdup(nullterm[j]); if (args[j] == NULL) - return errno; + return ENOMEM; } args[j] = NULL; } diff --git a/src/util/profile/profile_tcl.c b/src/util/profile/profile_tcl.c index 31a82f1b4..6a2476e47 100644 --- a/src/util/profile/profile_tcl.c +++ b/src/util/profile/profile_tcl.c @@ -1124,7 +1124,7 @@ static errcode_t iter_create(profile_t p, const char **nullterm, it = malloc(sizeof(*it)); if (it == NULL) - return errno; + return ENOMEM; { /* Memory leak! @@ -1138,11 +1138,11 @@ static errcode_t iter_create(profile_t p, const char **nullterm, for (count = 0; nullterm[count]; count++) ; args = calloc(count+1, sizeof(char *)); if (args == NULL) - return errno; + return ENOMEM; for (j = 0; j < count; j++) { args[j] = strdup(nullterm[j]); if (args[j] == NULL) - return errno; + return ENOMEM; } args[j] = NULL; } diff --git a/src/util/support/threads.c b/src/util/support/threads.c index 29613fd61..02c14e5de 100644 --- a/src/util/support/threads.c +++ b/src/util/support/threads.c @@ -1,7 +1,7 @@ /* * util/support/threads.c * - * Copyright 2004,2005,2006,2007 by the Massachusetts Institute of Technology. + * Copyright 2004,2005,2006,2007,2008 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -270,7 +270,7 @@ int k5_setspecific (k5_key_t keynum, void *value) int i; t = malloc(sizeof(*t)); if (t == NULL) - return errno; + return ENOMEM; for (i = 0; i < K5_KEY_MAX; i++) t->values[i] = 0; /* add to global linked list */ @@ -290,7 +290,7 @@ int k5_setspecific (k5_key_t keynum, void *value) int i; t = malloc(sizeof(*t)); if (t == NULL) - return errno; + return ENOMEM; for (i = 0; i < K5_KEY_MAX; i++) t->values[i] = 0; /* add to global linked list */ @@ -624,7 +624,7 @@ krb5int_mutex_alloc (k5_mutex_t **m) ptr = malloc (sizeof (k5_mutex_t)); if (ptr == NULL) - return errno; + return ENOMEM; err = k5_mutex_init (ptr); if (err) { free (ptr); -- 2.26.2