]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
cursor: Add note and guard for fr_cursor_intersect_* functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Apr 2020 16:34:31 +0000 (10:34 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Apr 2020 16:34:31 +0000 (10:34 -0600)
src/lib/util/cursor.c

index 5be7d695a5040b81c5300bbe57da4f9ccbbe3c8f..585c2ec777d5f56f3e23a00e7fd352c7dbb5bb2f 100644 (file)
@@ -403,6 +403,8 @@ void fr_cursor_merge(fr_cursor_t *cursor, fr_cursor_t *to_append)
 }
 
 /** Return the first item matching the iterator in cursor a and cursor b
+ *
+ * @note Both cursors must operate on the same list of items.
  *
  * @param[in] a                First cursor.
  * @param[in] b                Second cursor.
@@ -412,6 +414,8 @@ void *fr_cursor_intersect_head(fr_cursor_t *a, fr_cursor_t *b)
 {
        void *a_item, *b_item;
 
+       if (unlikely(a->head != b->head)) return NULL;
+
        a_item = fr_cursor_head(a);
        b_item = fr_cursor_head(b);
 
@@ -421,6 +425,8 @@ void *fr_cursor_intersect_head(fr_cursor_t *a, fr_cursor_t *b)
 }
 
 /** Return the next item matching the iterator in cursor a and cursor b
+ *
+ * @note Both cursors must operate on the same list of items.
  *
  * @param[in] a                First cursor.
  * @param[in] b                Second cursor.
@@ -430,6 +436,8 @@ void *fr_cursor_intersect_next(fr_cursor_t *a, fr_cursor_t *b)
 {
        fr_cursor_iter_t b_iter;
 
+       if (unlikely(a->head != b->head)) return NULL;
+
        /*
         *      If either of the iterators lack an iterator
         *      just use cursor_next...