Fix corner case in pairinsert/fr_cursor_insert
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 28 Feb 2014 18:27:31 +0000 (18:27 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 28 Feb 2014 18:27:31 +0000 (18:27 +0000)
If we previously inserted a value pair, with no next pointer, and iterated to the end of the list, then inserted another vp with a next pointer, pairnext would return NULL, even though there were more value pairs available.

src/lib/valuepair.c

index 3477cc7..17fbf60 100644 (file)
@@ -334,7 +334,6 @@ void pairinsert(vp_cursor_t *cursor, VALUE_PAIR *add)
        if (!*cursor->first) {
                *cursor->first = add;
                cursor->current = add;
-               cursor->next = cursor->current->next;
 
                return;
        }
@@ -368,6 +367,14 @@ void pairinsert(vp_cursor_t *cursor, VALUE_PAIR *add)
                cursor->current = add;
        }
 
+       /*
+        *      If there's no next cursor, and the pair we just inserted has additional
+        *      linked pairs, we need to set next to be the next VP in the list.
+        */
+       if (!cursor->next) {
+               cursor->next = add->next;
+       }
+
        cursor->last->next = add;
 }