summaryrefslogtreecommitdiff
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorKonst Mayer <cdlscpmv@gmail.com>2023-05-06 19:01:01 +0700
committerRafael Marçalo <raroma09@gmail.com>2023-05-09 22:29:15 +0100
commit5b6b582cb82777cde948aaf0b2e82e9995413d05 (patch)
tree666d8f36803c053909eac82f02f8edbf3bd1755f /src/autocmd.c
parent7aef680ad5b13193555ac03c8568069d9e30a0ce (diff)
Prevent use-after-free
g_slist_delete_link() frees the `lc` element, so we must not access it using `lc->next` after that.
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 2127d8e..f3a1875 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -192,12 +192,15 @@ gboolean autocmd_add(Client *c, char *name, gboolean delete)
/* delete the autocmd if bang was given */
if (delete) {
- GSList *lc;
+ GSList *lc, *next;
AutoCmd *cmd;
gboolean removed = false;
/* check if the group does already exists */
- for (lc = grp->cmds; lc; lc = lc->next) {
+ for (lc = grp->cmds; lc; lc = next) {
+ /* Save the next element in case this element is removed */
+ next = lc->next;
+
cmd = (AutoCmd*)lc->data;
/* if not bits match - skip the command */
if (!(cmd->bits & bits)) {