From ed2c4b3694a1d005a8553e26ccb8acd84626d916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Wed, 18 May 2005 04:44:40 +0000 Subject: [PATCH] (mkt_remove_entry): check if there isn't any entries in the keytab before removing any since that leads to bad pointer arithmetic and crashing. From: Wynn Wilkes . Make the function return KRB5_KT_NOTFOUND if the entry wasn't in the keytab (just like the filebased keytab). git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15169 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/keytab_memory.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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;