From d2b8a8c59aa918440eb6104525ac261a0c2b403a Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Fri, 7 Aug 1998 02:03:31 +0000 Subject: [PATCH] prof_tree.c: (profile_delete_node_relation): Fix bug where deleting a node would corrupt the linked list. (profile_add_node): Fix another linked list corruption problem where an insertion into the middle of the linked list didn't update a previous link. [krb5-libs/615] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10784 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/ChangeLog | 8 ++++++++ src/util/profile/prof_tree.c | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index c8bc9ce81..8addd10cd 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,11 @@ +1998-08-06 Theodore Ts'o + + * prof_tree.c (profile_delete_node_relation): Fix bug where + deleting a node would corrupt the linked list. + (profile_add_node): Fix another linked list corruption + problem where an insertion into the middle of the linked + list didn't update a previous link. [krb5-libs/615] + Mon Mar 2 16:19:58 1998 Ezra Peisach * Makefile.in: Integrate in the krb5 build tree rules. diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index 3db7dc625..f4dc9751b 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -145,9 +145,14 @@ errcode_t profile_add_node(section, name, value, ret_node) if (section->value) return PROF_ADD_NOT_SECTION; + /* + * Find the place to insert the new node. We look for the + * place *after* the last match of the node name, since + * order matters. + */ for (p=section->first_child, last = 0; p; last = p, p = p->next) { cmp = strcmp(p->name, name); - if (cmp >= 0) + if (cmp > 0) break; } retval = profile_create_node(name, value, &new); @@ -155,19 +160,14 @@ errcode_t profile_add_node(section, name, value, ret_node) return retval; new->group_level = section->group_level+1; new->parent = section; - if (cmp == 0) { - do { - last = p; - p = p->next; - } while (p && strcmp(p->name, name) == 0); - } new->prev = last; + new->next = p; + if (p) + p->prev = new; if (last) last->next = new; else section->first_child = new; - if (p) - new->next = p; if (ret_node) *ret_node = new; return 0; @@ -317,7 +317,7 @@ errcode_t profile_delete_node_relation(section, name) section->first_child = p->next; next = p->next; if (p->next) - p->next->prev = p; + p->next->prev = p->prev; profile_free_node(p); p = next; } -- 2.26.2