From 0d1aad0af427b999d7242ce41a532c9dd7ee1c69 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 8 Jan 2016 20:21:54 +0100 Subject: [PATCH] rename workspace: fix heap-use-after-free --- src/commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands.c b/src/commands.c index 03ae0ae0..0c6ff127 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2001,6 +2001,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) { } /* Change the name and try to parse it as a number. */ + /* old_name might refer to workspace->name, so copy it before free()ing */ + char *old_name_copy = sstrdup(old_name); FREE(workspace->name); workspace->name = sstrdup(new_name); @@ -2041,7 +2043,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) { ewmh_update_desktop_viewport(); ewmh_update_current_desktop(); - startup_sequence_rename_workspace(old_name, new_name); + startup_sequence_rename_workspace(old_name_copy, new_name); + free(old_name_copy); } /*