From bd19b798ba1583651b729910fbb5508e6cb2b4e7 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Tue, 20 Oct 2009 00:48:46 +0000 Subject: [PATCH] fix some Coverity reported defects in naming extensions git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22948 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/authdata.c | 44 ++++++++++++++++++----------------- src/lib/krb5/krb/copy_auth.c | 1 + src/lib/krb5/krb/pac.c | 3 --- src/lib/krb5/krb/rd_req_dec.c | 4 +++- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/lib/krb5/krb/authdata.c b/src/lib/krb5/krb/authdata.c index 6e1b9b5b1..c5992aded 100644 --- a/src/lib/krb5/krb/authdata.c +++ b/src/lib/krb5/krb/authdata.c @@ -408,19 +408,14 @@ krb5_authdata_context_init(krb5_context kcontext, context = calloc(1, sizeof(*context)); if (kcontext == NULL) { - if (tables != NULL) - krb5int_free_plugin_dir_data(tables); - krb5int_close_plugin_dirs(&context->plugins); - return ENOMEM; + code = ENOMEM; + goto cleanup; } context->magic = KV5M_AUTHDATA_CONTEXT; context->modules = calloc(n_modules, sizeof(context->modules[0])); if (context->modules == NULL) { - if (tables != NULL) - krb5int_free_plugin_dir_data(tables); - krb5int_close_plugin_dirs(&context->plugins); - free(kcontext); - return ENOMEM; + code = ENOMEM; + goto cleanup; } context->n_modules = n_modules; @@ -428,26 +423,28 @@ krb5_authdata_context_init(krb5_context kcontext, for (i = 0, k = 0, code = 0; i < n_tables - internal_count; i++) { code = k5_ad_init_modules(kcontext, context, tables[i], &k); if (code != 0) - break; + goto cleanup; } - if (code == 0) { - for (i = 0; i < internal_count; i++) { - code = k5_ad_init_modules(kcontext, context, authdata_systems[i], &k); - if (code != 0) - break; - } + for (i = 0; i < internal_count; i++) { + code = k5_ad_init_modules(kcontext, context, authdata_systems[i], &k); + if (code != 0) + goto cleanup; } + context->plugins = plugins; + +cleanup: if (tables != NULL) krb5int_free_plugin_dir_data(tables); - context->plugins = plugins; - - if (code != 0) + if (code != 0) { + krb5int_close_plugin_dirs(&plugins); krb5_authdata_context_free(kcontext, context); - else + } else { + /* plugins is owned by context now */ *pcontext = context; + } return code; } @@ -596,9 +593,14 @@ krb5_authdata_export_authdata(krb5_context kcontext, if (authdata != NULL) authdata[len] = NULL; + if (code != 0) { + krb5_free_authdata(kcontext, authdata); + return code; + } + *pauthdata = authdata; - return code; + return 0; } krb5_error_code diff --git a/src/lib/krb5/krb/copy_auth.c b/src/lib/krb5/krb/copy_auth.c index ba51f3808..6f36b2698 100644 --- a/src/lib/krb5/krb/copy_auth.c +++ b/src/lib/krb5/krb/copy_auth.c @@ -375,6 +375,7 @@ krb5_verify_authdata_kdc_issued(krb5_context context, if (code != 0) { krb5_free_ad_kdcissued(context, ad_kdci); krb5_free_data(context, data2); + return code; } krb5_free_data(context, data2); diff --git a/src/lib/krb5/krb/pac.c b/src/lib/krb5/krb/pac.c index 297e89550..58a28cd17 100644 --- a/src/lib/krb5/krb/pac.c +++ b/src/lib/krb5/krb/pac.c @@ -1258,9 +1258,6 @@ mspac_get_attribute(krb5_context kcontext, krb5_error_code code; krb5_ui_4 type; - value->data = NULL; - value->length = 0; - if (display_value != NULL) { display_value->data = NULL; display_value->length = 0; diff --git a/src/lib/krb5/krb/rd_req_dec.c b/src/lib/krb5/krb/rd_req_dec.c index 48503d333..0861794dd 100644 --- a/src/lib/krb5/krb/rd_req_dec.c +++ b/src/lib/krb5/krb/rd_req_dec.c @@ -132,7 +132,7 @@ krb5_rd_req_decrypt_tkt_part(krb5_context context, const krb5_ap_req *req, req->ticket); if (retval == 0) { - krb5_principal tmp; + krb5_principal tmp = NULL; /* * We overwrite ticket->server to be the principal @@ -152,6 +152,8 @@ krb5_rd_req_decrypt_tkt_part(krb5_context context, const krb5_ap_req *req, if (retval == 0) { krb5_free_principal(context, req->ticket->server); req->ticket->server = tmp; + } else { + krb5_free_principal(context, tmp); } (void) krb5_free_keytab_entry_contents(context, &ktent); break; -- 2.26.2