Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential crash when executing commands in bindings #1002

Closed
wants to merge 1 commit into from

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented Mar 30, 2020

The function run_prompt_command may reallocate the array run_request,
invalidating the pointer to the current request if it was inside
run_request. The resulting use-after-free would cause occasional crashes.

Fixes #1001

@koutcher
Copy link
Collaborator

koutcher commented Apr 1, 2020

Great catch, thanks for tracking down the issue. As the problem is limited to the use of the flags in the end of exec_run_request(), I'd be more in favor of keeping a copy of the flags. Something like:

diff --git a/src/prompt.c b/src/prompt.c
index 506b32b..df20549 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -1096,6 +1096,7 @@ exec_run_request(struct view *view, struct run_request *req)
 	char cmd[SIZEOF_MED_STR];
 	const char *req_argv[SIZEOF_ARG];
 	int req_argc = 0;
+	struct run_request_flags req_flags = req->flags;
 
 	if (!argv_to_string(req->argv, cmd, sizeof(cmd), " ")
 	    || !argv_from_string_no_quotes(req_argv, &req_argc, cmd)
@@ -1132,13 +1133,13 @@ exec_run_request(struct view *view, struct run_request *req)
 	free(argv);
 
 	if (request == REQ_NONE) {
-		if (req->flags.confirm && !confirmed)
+		if (req_flags.confirm && !confirmed)
 			request = REQ_NONE;
 
-		else if (req->flags.exit)
+		else if (req_flags.exit)
 			request = REQ_QUIT;
 
-		else if (!req->flags.internal && watch_dirty(&view->watch))
+		else if (!req_flags.internal && watch_dirty(&view->watch))
 			request = REQ_REFRESH;
 
 	}

What do you think ?

@krobelus
Copy link
Contributor Author

krobelus commented Apr 1, 2020

Yeah your fix is cleaner, let's do that instead; closing this.
Thank you!

@krobelus krobelus closed this Apr 1, 2020
The function run_prompt_command may reallocate the run_request,
invalidating the pointer to the current request if it was inside
run_request. The resulting use-after-free would cause occasional crashes.

Fixes jonas#1001
@krobelus
Copy link
Contributor Author

krobelus commented Apr 4, 2020

Reopening with your suggestion so this doesn't get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use-after-free when sourcing specific tigrc from binding
2 participants