diff --git a/lib/krb5/keytab_memory.c b/lib/krb5/keytab_memory.c index cdb30a340..11a55bfa8 100644 --- a/lib/krb5/keytab_memory.c +++ b/lib/krb5/keytab_memory.c @@ -133,7 +133,13 @@ mkt_remove_entry(krb5_context context, { struct mkt_data *d = id->data; krb5_keytab_entry *e, *end; + int found = 0; + if (d->num_entries == 0) { + krb5_clear_error_string(context); + return KRB5_KT_NOTFOUND; + } + /* do this backwards to minimize copying */ for(end = d->entries + d->num_entries, e = end - 1; e >= d->entries; e--) { if(krb5_kt_compare(context, e, entry->principal, @@ -143,8 +149,13 @@ mkt_remove_entry(krb5_context context, memset(end - 1, 0, sizeof(*end)); d->num_entries--; end--; + found = 1; } } + if (!found) { + krb5_clear_error_string (context); + return KRB5_KT_NOTFOUND; + } e = realloc(d->entries, d->num_entries * sizeof(*d->entries)); if(e != NULL) d->entries = e;