From 50dc49f35a41de7b59c27c6f796f3ec9a9a4878a Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Fri, 13 Mar 2020 03:50:37 +0900 Subject: Limit workspace numbers within 0..INT32_MAX See https://github.com/i3/i3/commit/83c7aff089a6728b6e522d934d656a8e09463112 --- sway/ipc-json.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sway/ipc-json.c') diff --git a/sway/ipc-json.c b/sway/ipc-json.c index d3731092..1ebc3bd2 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -384,8 +384,19 @@ static json_object *ipc_json_describe_scratchpad_output(void) { static void ipc_json_describe_workspace(struct sway_workspace *workspace, json_object *object) { - int num = isdigit(workspace->name[0]) ? atoi(workspace->name) : -1; - + int num; + if (isdigit(workspace->name[0])) { + errno = 0; + char *endptr = NULL; + long long parsed_num = strtoll(workspace->name, &endptr, 10); + if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == workspace->name) { + num = -1; + } else { + num = (int) parsed_num; + } + } else { + num = -1; + } json_object_object_add(object, "num", json_object_new_int(num)); json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); json_object_object_add(object, "output", workspace->output ? -- cgit v1.2.3-54-g00ecf