diff options
| author | Greg Hudson <ghudson@mit.edu> | 2013-05-10 14:01:48 -0400 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2013-05-14 13:31:41 -0400 |
| commit | 6350fd0c909d84c00200885e722cc902049ada05 (patch) | |
| tree | a880eae4b875d2b94747048a7092f619c79d33c2 /src/lib/krb5/keytab | |
| parent | 1799f7b5d9cf4390148248d603d99a3695ddfafe (diff) | |
| download | krb5-6350fd0c909d84c00200885e722cc902049ada05.tar.gz krb5-6350fd0c909d84c00200885e722cc902049ada05.tar.xz krb5-6350fd0c909d84c00200885e722cc902049ada05.zip | |
Assume mutex locking cannot fail
Locking and unlocking a non-recursive mutex is a simple memory
operation and should not fail on any reasonable platform with correct
usage. A pthread mutex can return EDEADLK on lock or EPERM on unlock,
or EINVAL if the mutex is uninitialized, but all of these conditions
would reflect serious bugs in the calling code.
Change the k5_mutex_lock and k5_mutex_unlock wrappers to return void
and adjust all call sites. Propagate this change through
k5_cc_mutex_lock and k5_cc_mutex_unlock as well.
Diffstat (limited to 'src/lib/krb5/keytab')
| -rw-r--r-- | src/lib/krb5/keytab/kt_file.c | 24 | ||||
| -rw-r--r-- | src/lib/krb5/keytab/kt_memory.c | 40 | ||||
| -rw-r--r-- | src/lib/krb5/keytab/ktbase.c | 9 |
3 files changed, 17 insertions, 56 deletions
diff --git a/src/lib/krb5/keytab/kt_file.c b/src/lib/krb5/keytab/kt_file.c index 8dcf787ede..82d3c418c9 100644 --- a/src/lib/krb5/keytab/kt_file.c +++ b/src/lib/krb5/keytab/kt_file.c @@ -272,9 +272,7 @@ krb5_ktfile_get_entry(krb5_context context, krb5_keytab id, int was_open; char *princname; - kerror = KTLOCK(id); - if (kerror) - return kerror; + KTLOCK(id); if (KTFILEP(id) != NULL) { was_open = 1; @@ -452,9 +450,7 @@ krb5_ktfile_start_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor * krb5_error_code retval; long *fileoff; - retval = KTLOCK(id); - if (retval) - return retval; + KTLOCK(id); if (KTITERS(id) == 0) { if ((retval = krb5_ktfileint_openr(context, id))) { @@ -496,9 +492,7 @@ krb5_ktfile_get_next(krb5_context context, krb5_keytab id, krb5_keytab_entry *en krb5_keytab_entry cur_entry; krb5_error_code kerror; - kerror = KTLOCK(id); - if (kerror) - return kerror; + KTLOCK(id); if (KTFILEP(id) == NULL) { KTUNLOCK(id); return KRB5_KT_IOERR; @@ -527,9 +521,7 @@ krb5_ktfile_end_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursor krb5_error_code kerror; free(*cursor); - kerror = KTLOCK(id); - if (kerror) - return kerror; + KTLOCK(id); KTITERS(id)--; if (KTFILEP(id) != NULL && KTITERS(id) == 0) kerror = krb5_ktfileint_close(context, id); @@ -817,9 +809,7 @@ krb5_ktfile_add(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry) { krb5_error_code retval; - retval = KTLOCK(id); - if (retval) - return retval; + KTLOCK(id); if (KTFILEP(id)) { /* Iterator(s) active -- no changes. */ KTUNLOCK(id); @@ -853,9 +843,7 @@ krb5_ktfile_remove(krb5_context context, krb5_keytab id, krb5_keytab_entry *entr krb5_error_code kerror; krb5_int32 delete_point; - kerror = KTLOCK(id); - if (kerror) - return kerror; + KTLOCK(id); if (KTFILEP(id)) { /* Iterator(s) active -- no changes. */ KTUNLOCK(id); diff --git a/src/lib/krb5/keytab/kt_memory.c b/src/lib/krb5/keytab/kt_memory.c index 5ec304af0e..e89fdcb4dc 100644 --- a/src/lib/krb5/keytab/kt_memory.c +++ b/src/lib/krb5/keytab/kt_memory.c @@ -249,9 +249,7 @@ krb5_mkt_resolve(krb5_context context, const char *name, krb5_keytab *id) *id = NULL; /* First determine if a memory keytab of this name already exists */ - err = KTGLOCK; - if (err) - return err; + KTGLOCK; for (list = krb5int_mkt_list; list; list = list->next) { if (strcmp(name,KTNAME(list->keytab)) == 0) @@ -271,9 +269,7 @@ krb5_mkt_resolve(krb5_context context, const char *name, krb5_keytab *id) } /* Increment the reference count on the keytab we found or created. */ - err = KTLOCK(list->keytab); - if (err) - goto done; + KTLOCK(list->keytab); KTREFCNT(list->keytab)++; KTUNLOCK(list->keytab); *id = list->keytab; @@ -301,9 +297,7 @@ krb5_mkt_close(krb5_context context, krb5_keytab id) krb5_error_code err = 0; /* First determine if a memory keytab of this name already exists */ - err = KTGLOCK; - if (err) - return(err); + KTGLOCK; for (listp = &krb5int_mkt_list; *listp; listp = &((*listp)->next)) { @@ -320,10 +314,7 @@ krb5_mkt_close(krb5_context context, krb5_keytab id) } /* reduce the refcount and return */ - err = KTLOCK(id); - if (err) - goto done; - + KTLOCK(id); KTREFCNT(id)--; KTUNLOCK(id); @@ -388,9 +379,7 @@ krb5_mkt_get_entry(krb5_context context, krb5_keytab id, int found_wrong_kvno = 0; krb5_boolean similar = 0; - err = KTLOCK(id); - if (err) - return err; + KTLOCK(id); for (cursor = KTLINK(id); cursor && cursor->entry; cursor = cursor->next) { entry = cursor->entry; @@ -480,12 +469,7 @@ krb5_mkt_get_name(krb5_context context, krb5_keytab id, char *name, unsigned int krb5_error_code KRB5_CALLCONV krb5_mkt_start_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursorp) { - krb5_error_code err = 0; - - err = KTLOCK(id); - if (err) - return(err); - + KTLOCK(id); *cursorp = (krb5_kt_cursor)KTLINK(id); KTUNLOCK(id); @@ -502,9 +486,7 @@ krb5_mkt_get_next(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry krb5_mkt_cursor mkt_cursor = (krb5_mkt_cursor)*cursor; krb5_error_code err = 0; - err = KTLOCK(id); - if (err) - return err; + KTLOCK(id); if (mkt_cursor == NULL) { KTUNLOCK(id); @@ -548,9 +530,7 @@ krb5_mkt_add(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry) krb5_error_code err = 0; krb5_mkt_cursor cursor; - err = KTLOCK(id); - if (err) - return err; + KTLOCK(id); cursor = (krb5_mkt_cursor)malloc(sizeof(krb5_mkt_link)); if (cursor == NULL) { @@ -605,9 +585,7 @@ krb5_mkt_remove(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry) krb5_mkt_cursor *pcursor, next; krb5_error_code err = 0; - err = KTLOCK(id); - if (err) - return err; + KTLOCK(id); if ( KTLINK(id) == NULL ) { err = KRB5_KT_NOTFOUND; diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c index 848b047f45..0d39b2940c 100644 --- a/src/lib/krb5/keytab/ktbase.c +++ b/src/lib/krb5/keytab/ktbase.c @@ -123,11 +123,8 @@ krb5_kt_register(krb5_context context, const krb5_kt_ops *ops) { const struct krb5_kt_typelist *t; struct krb5_kt_typelist *newt; - krb5_error_code err; - err = k5_mutex_lock(&kt_typehead_lock); - if (err) - return err; + k5_mutex_lock(&kt_typehead_lock); for (t = kt_typehead; t && strcmp(t->ops->prefix,ops->prefix);t = t->next) ; if (t) { @@ -195,9 +192,7 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) *ktid = (krb5_keytab) 0; - err = k5_mutex_lock(&kt_typehead_lock); - if (err) - goto cleanup; + k5_mutex_lock(&kt_typehead_lock); tlist = kt_typehead; /* Don't need to hold the lock, since entries are never modified or removed once they're in the list. Just need to protect |
