Address code review: add buffer overflow safety in drop_append_request_keys

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/cdeecb3c-8589-4622-8f6b-21b724e4d5fd

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-09 15:41:12 +00:00 committed by GitHub
parent 0f47a23c36
commit 3a8253e747
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -415,11 +415,11 @@ get_errno_name(int err) {
static int
drop_append_request_keys(Window *w, char *buf, size_t bufsize) {
int sz = 0;
if (w->drop.current_request_x)
if (w->drop.current_request_x && sz < (int)bufsize - 1)
sz += snprintf(buf + sz, bufsize - sz, ":x=%d", (int)w->drop.current_request_x);
if (w->drop.current_request_y)
if (w->drop.current_request_y && sz < (int)bufsize - 1)
sz += snprintf(buf + sz, bufsize - sz, ":y=%d", (int)w->drop.current_request_y);
if (w->drop.current_request_Y)
if (w->drop.current_request_Y && sz < (int)bufsize - 1)
sz += snprintf(buf + sz, bufsize - sz, ":Y=%d", (int)w->drop.current_request_Y);
return sz;
}