prof_tree.c: (profile_delete_node_relation): Fix bug where deleting a
authorTheodore Tso <tytso@mit.edu>
Fri, 7 Aug 1998 02:03:31 +0000 (02:03 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 7 Aug 1998 02:03:31 +0000 (02:03 +0000)
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
src/util/profile/prof_tree.c

index c8bc9ce8187c57d4c036f668eafdf31093771f81..8addd10cd9d87b2e25b90b4cf0b1652275775cf2 100644 (file)
@@ -1,3 +1,11 @@
+1998-08-06  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+       * 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  <epeisach@mit.edu>
 
        * Makefile.in: Integrate in the krb5 build tree rules.
index 3db7dc625eab2abe6f8e4127274896bae7499546..f4dc9751bb3ad2b7c5d7c7fc376b9a446e7e84dd 100644 (file)
@@ -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;
        }