From: Tom Yu Date: Wed, 16 Jul 2008 22:35:21 +0000 (+0000) Subject: Check return value from k5_mutex_lock() to partially mitigate some X-Git-Tag: krb5-1.7-alpha1~594 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d03dc681d44f6cb71f9d8271ba042d3390b9d4d3;p=krb5.git Check return value from k5_mutex_lock() to partially mitigate some assertion failures when mutexes get destroyed out from under us. ticket: 5962 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20529 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/gssapi/mechglue/g_initialize.c b/src/lib/gssapi/mechglue/g_initialize.c index d47499caf..5fbe26fcf 100644 --- a/src/lib/gssapi/mechglue/g_initialize.c +++ b/src/lib/gssapi/mechglue/g_initialize.c @@ -101,7 +101,9 @@ gss_OID *oid; *minor_status = 0; - k5_mutex_lock(&g_mechListLock); + minor_status = k5_mutex_lock(&g_mechListLock); + if (minor_status) + return GSS_S_FAILURE; aMech = g_mechList; while (aMech != NULL) { @@ -179,7 +181,9 @@ gss_OID_set *mechSet; * need to lock the g_mechSet in case someone tries to update it while * I'm copying it. */ - (void) k5_mutex_lock(&g_mechSetLock); + minorStatus = k5_mutex_lock(&g_mechSetLock); + if (minorStatus) + return GSS_S_FAILURE; /* allocate space for the oid structures */ if (((*mechSet)->elements = @@ -253,7 +257,8 @@ build_mechSet(void) * since we are accessing parts of the mechList which could be * modified. */ - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return GSS_S_FAILURE; updateMechList(); @@ -261,7 +266,8 @@ build_mechSet(void) * we need to lock the mech set so that no one else will * try to read it as we are re-creating it */ - (void) k5_mutex_lock(&g_mechSetLock); + if (k5_mutex_lock(&g_mechSetLock) != 0) + return GSS_S_FAILURE; /* if the oid list already exists we must free it first */ free_mechSet(); @@ -339,7 +345,8 @@ const gss_OID oid; char *modOptions = NULL; /* make sure we have fresh data */ - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return NULL; updateMechList(); if ((aMech = searchMechList(oid)) == NULL || @@ -373,7 +380,8 @@ gssint_mech_to_oid(const char *mechStr, gss_OID* oid) return (GSS_S_COMPLETE); /* ensure we have fresh data */ - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return GSS_S_FAILURE; updateMechList(); (void) k5_mutex_unlock(&g_mechListLock); @@ -406,7 +414,8 @@ gssint_oid_to_mech(const gss_OID oid) return (M_DEFAULT); /* ensure we have fresh data */ - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return GSS_S_FAILURE; updateMechList(); aMech = searchMechList(oid); (void) k5_mutex_unlock(&g_mechListLock); @@ -434,7 +443,8 @@ gssint_get_mechanisms(char *mechArray[], int arrayLen) return (GSS_S_CALL_INACCESSIBLE_WRITE); /* ensure we have fresh data */ - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return GSS_S_FAILURE; updateMechList(); (void) k5_mutex_unlock(&g_mechListLock); @@ -568,7 +578,8 @@ gssint_get_mechanism(gss_OID oid) if (gssint_initialize_library()) return NULL; - (void) k5_mutex_lock(&g_mechListLock); + if (k5_mutex_lock(&g_mechListLock) != 0) + return GSS_S_FAILURE; /* check if the mechanism is already loaded */ if ((aMech = searchMechList(oid)) != NULL && aMech->mech) { (void) k5_mutex_unlock(&g_mechListLock); diff --git a/src/lib/krb5/ccache/cc_file.c b/src/lib/krb5/ccache/cc_file.c index 62061497a..134cbfbb3 100644 --- a/src/lib/krb5/ccache/cc_file.c +++ b/src/lib/krb5/ccache/cc_file.c @@ -1503,7 +1503,9 @@ static krb5_error_code dereference(krb5_context context, krb5_fcc_data *data) free(data->filename); zap(data->buf, sizeof(data->buf)); if (data->file >= 0) { - k5_mutex_lock(&data->lock); + kerr = k5_mutex_lock(&data->lock); + if (kerr) + return kerr; krb5_fcc_close_file(context, data); k5_mutex_unlock(&data->lock); } diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index 7bd989485..1cd982e14 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -75,7 +75,8 @@ void com_err_terminate(void) #endif k5_key_delete(K5_KEY_COM_ERR); k5_mutex_destroy(&com_err_hook_lock); - k5_mutex_lock(&et_list_lock); + if (k5_mutex_lock(&et_list_lock) != 0) + return; for (e = et_list_dynamic; e; e = enext) { enext = e->next; free(e);