]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
watcher: Make sure to re-activate the correct entry after a callback
authorTobias Brunner <tobias@strongswan.org>
Tue, 18 Apr 2023 13:55:10 +0000 (15:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 27 Apr 2023 11:52:34 +0000 (13:52 +0200)
Since the same FD may be added multiple times (e.g. with separate
callbacks for WATCHER_READ and WATCHER_WRITE), the previous check
might not have found the correct entry.  As the entry can't be removed
while in a callback, the pointer comparison is fine.

src/libstrongswan/processing/watcher.c

index c4d11e9fc6ad24eddfb6edb277cf78bdd0bd1c9c..f78a6c5b1a1a266477a9ba0aaa5f38886b193907 100644 (file)
@@ -153,6 +153,8 @@ static entry_t *remove_entry(private_watcher_t *this, entry_t *entry,
  * Data we pass on for an async notification
  */
 typedef struct {
+       /** triggering entry */
+       entry_t *entry;
        /** file descriptor */
        int fd;
        /** event type */
@@ -227,7 +229,7 @@ static void notify_end(notify_data_t *data)
        this->mutex->lock(this->mutex);
        for (entry = this->fds; entry; prev = entry, entry = entry->next)
        {
-               if (entry->fd == data->fd)
+               if (entry == data->entry)
                {
                        if (!data->keep)
                        {
@@ -277,6 +279,7 @@ static void notify(private_watcher_t *this, entry_t *entry,
 
        /* get a copy of entry for async job, but with specific event */
        INIT(data,
+               .entry = entry,
                .fd = entry->fd,
                .event = event,
                .cb = entry->cb,