]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
After malloc/realloc/calloc failures, return ENOMEM explicitly instead
authorKen Raeburn <raeburn@mit.edu>
Wed, 30 Apr 2008 23:18:21 +0000 (23:18 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 30 Apr 2008 23:18:21 +0000 (23:18 +0000)
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

21 files changed:
src/appl/bsd/compat_recv.c
src/clients/ksu/ccache.c
src/clients/ksu/heuristic.c
src/clients/ksu/main.c
src/lib/crypto/des/string2key.c
src/lib/crypto/dk/dk_encrypt.c
src/lib/crypto/pbkdf2.c
src/lib/kadm5/alt_prof.c
src/lib/kadm5/srv/server_dict.c
src/lib/krb5/ccache/cc_memory.c
src/lib/krb5/os/hostaddr.c
src/lib/krb5/os/init_os_ctx.c
src/lib/krb5/os/localaddr.c
src/lib/krb5/os/locate_kdc.c
src/util/et/error_message.c
src/util/et/init_et.c
src/util/profile/prof_file.c
src/util/profile/prof_init.c
src/util/profile/profile.swg
src/util/profile/profile_tcl.c
src/util/support/threads.c

index c76c4142c6d0d6ef73c2968177a7e2df67899dae..1e54941e1e215d1a8de362fb15096b96e90a82cb 100644 (file)
@@ -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,
index 5e9c5ec511dae1f84f0e909d1ada3882f20366ce..ec8f2af0e0c4fa7e8f0fd02bc177929ea8b9ee25 100644 (file)
@@ -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;
index 2eeadd454248e1f94c79a1f409d9132c32d1d146..80482bebbca9ec7031b1ea225ad1aad1ff106b68 100644 (file)
@@ -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]){
index f3d8440694f7d618546f1fb51eaf637bf0f9f11d..3329bd78ac9ce6329603ab9705f6a2740ae5aa5f 100644 (file)
@@ -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++){
index 4fe9e4799a5a2b58c25f048c24c3dd5f88c5d28a..016ae3e201be140e7f093584e125353519809cd0 100644 (file)
@@ -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);
index 5b2d3e793746a556ba2b3dc63119746d6e900b1d..750f43ffed14ad55de0566169417513e818dcdb4 100644 (file)
@@ -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);
index ff446dbde74ab3567017c1418247936c882c00a0..a6cce1cd0f37da301bb2e07ada27ac52694030be 100644 (file)
@@ -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.  */
index 6802090d5667de9171b639991c84cb4265411d7a..5724c14031544decf531747caadd72b63c45dbbb 100644 (file)
@@ -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);
index 4f41b0d4148b11c74dbff11fcaa7265976ab0c24..ece7831c9000146c32df6f43e892bb8c98aa21ab 100644 (file)
@@ -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;
index 173d0039d63c18ee74374a73ccdc158a59a5dc9d..d5c0493baf0bdf3f97d00f86043ec24a7986eeef 100644 (file)
@@ -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);
index 76eb1273dcdb4a1cac3579765aca5b8b738bb7f1..eaef098588750f68d4c53e3553ad06884c4dfb64 100644 (file)
@@ -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;
index 16ff0435f721bba3926d9394c9fbf818504eda43..132816d0599be86e60082c2c4b4eba34e1df982a 100644 (file)
@@ -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) {
index e139ca4d30f1d87bccb68b04e08336ec14c9b08b..ea8c9a2051894f1661324e8001a18a494bc57c6e 100644 (file)
@@ -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;
     }
index 7605328aeee817e75f50d471c9fef5713ecf731a..aedb14a888895dd43dabd78cb168f3f22949e2ec 100644 (file)
@@ -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;
index 6a3a6ccaac45d67c8fb83624fc2db04e2cd15c36..7bd98948537f418fad4d3a35f0ed0618c5be6ea1 100644 (file)
@@ -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;
 
index b0a406403174ecc3beb06ebc984469a8b9f58879..e397a27060e72b7f8b93f918d2e797d094fa1cde 100644 (file)
@@ -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;
index 44d63a8baa3fce185af102d9de1a6521be39b0e9..c6f15fee599ff1ea0f173f318aa8b2d4e053cb58 100644 (file)
@@ -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);
index e5c6f9c8c5b3535360c197d3595a922858d8ed2e..9a5659a8ce1c220ee55741674c205c234adff7a9 100644 (file)
@@ -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;
index 2e75bb4c6dc5519a9fe9a93157d5d9539831507d..074a97b9ef614d8b1d7a73ae6eafc557a3218062 100644 (file)
@@ -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;
     }
index 31a82f1b41a9b5c685ac68d280c1e57bd09e1fb7..6a2476e47b3be686fcdffba6c54441e0afc18074 100644 (file)
@@ -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;
     }
index 29613fd616e139c4efc34d8499b5dd1d0976eeb4..02c14e5de0a6c9b3fe38ed4180525bb2a7cb5c9b 100644 (file)
@@ -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);