]> git.ipfire.org Git - thirdparty/strongswan.git/commit
array: Warn about caveat with array_remove_at() and value based arrays
authorTobias Brunner <tobias@strongswan.org>
Thu, 11 Sep 2014 15:29:21 +0000 (17:29 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 11 Sep 2014 15:52:00 +0000 (17:52 +0200)
commitc641974de001247e100638dbe816bd1cd90f3f30
tree83911d378a506bbb461e8ad6e93f20bcedafb781
parent92b76384a01366e45a6748ce0c921903b47bab78
array: Warn about caveat with array_remove_at() and value based arrays

Because enumerate() for value based arrays returns a pointer directly to
the internal array elements and because array_remove_at() or rather the
called array_remove() may move elements over the element at the currently
enumerated position, the pointer passed to enumerate() will point to a
different array element after the array_remove_at() call.  The caller
will thus operate on the wrong element if that pointer is accessed again
before calling enumerate().

For performance reasons we currently don't change the implementation to copy
each array element during enumeration to a private member of the enumerator and
return a pointer to that.  Similarly, due to the danger of subtle bugs we don't
remember the pointer passed to enumerate() to later redirect it to a copy
created during the array_remove_at() call.
src/libstrongswan/collections/array.h