]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
(more) After malloc/realloc/calloc/strdup/asprintf failures, use
authorKen Raeburn <raeburn@mit.edu>
Wed, 30 Apr 2008 23:46:29 +0000 (23:46 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 30 Apr 2008 23:46:29 +0000 (23:46 +0000)
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
src/krb524/krb524d.c
src/lib/gssapi/krb5/gssapi_krb5.c
src/lib/kadm5/srv/svr_principal.c
src/lib/kdb/kdb5.c
src/lib/krb5/os/changepw.c
src/lib/krb5/os/init_os_ctx.c
src/lib/krb5/os/localaddr.c
src/lib/krb5/os/sendto_kdc.c
src/util/support/plugins.c

index e9dcf86107ebf2d68aa1ae87331fc8ab07849796..82b1c7768850b09752d9194286603ad800ea9da2 100644 (file)
@@ -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;
     }
index c33efa37be51d60d89ca2c3f34b0e340d32a01b4..202cda920c27030c2b519c8039d19e2549a28ea5 100644 (file)
@@ -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;
        }
index 224484f44bf64221b062eda4e9fa5d9653072779..95a876371126af7578e3146a4281dbc25e09a6bc 100644 (file)
@@ -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)
index a7636e770b4271b8882b71d516578b82fdd62170..702c175b2ed820cfc8173e42124c99f1789907c5 100644 (file)
@@ -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) {
index 2b6ed2c642eac3e19c5f11034d67b56bd2f4babf..2a6b4686d241ba7e6d68bc6d489b40bb31fc82f5 100644 (file)
@@ -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)
index 816713dc44185272b7840ce705ab8947e061fb80..275f61a63bc222f0433cd8e1391845a034bb14df 100644 (file)
@@ -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;
        }
index 132816d0599be86e60082c2c4b4eba34e1df982a..06a5b6bfa81638592dec573d7c6a67f28df15ede 100644 (file)
@@ -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;
     }
index ea8c9a2051894f1661324e8001a18a494bc57c6e..55180808e46ae1edd3e137f4f119686ca241405c 100644 (file)
@@ -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;
        }
 
index 050aec5f95c308ad380f03ff2d7a7ecc14e463da..cd40cb67bb170774b0b14deeed647f1c32bb7df3 100644 (file)
@@ -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;
                }
            }
index 90e16f388237415e05e00f0996e5aa872f852387..3f71f43a57ccb6372773000120228e8a9b4aeccd 100644 (file)
@@ -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;