From 05b288e75475123aa766d6f96d8f1ce39da6f7f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 15:34:56 +0000 Subject: [PATCH] Address code review: use PATH_MAX buffer and move os import to top Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/da8b4577-3de8-4784-afc0-c1967f605dec Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- kitty/dnd.c | 7 ++++--- kitty_tests/dnd.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kitty/dnd.c b/kitty/dnd.c index 0ed4a8f34..eae6cdeeb 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -2653,10 +2653,11 @@ dnd_test_probe_state(PyObject *self UNUSED, PyObject *args) { if (mi.is_uri_list && mi.remote_items && uri_idx < mi.num_remote_items) { const char *name = mi.remote_items[uri_idx].dir_entry_name; if (name) { - char path[4096]; - snprintf(path, sizeof(path), "%s/%zu/%s", + char path[PATH_MAX + 1]; + int n = snprintf(path, sizeof(path), "%s/%zu/%s", w->drag_source.base_dir_for_remote_items, uri_idx, name); - return PyUnicode_FromString(path); + if (n <= 0 || (size_t)n >= sizeof(path)) Py_RETURN_NONE; + return PyUnicode_FromStringAndSize(path, (Py_ssize_t)n); } } #undef mi diff --git a/kitty_tests/dnd.py b/kitty_tests/dnd.py index f78e870cd..012647e8b 100644 --- a/kitty_tests/dnd.py +++ b/kitty_tests/dnd.py @@ -2,6 +2,7 @@ # License: GPL v3 Copyright: 2026, Kovid Goyal import errno +import os import re from base64 import standard_b64encode from contextlib import contextmanager @@ -2934,7 +2935,6 @@ class TestDnDProtocol(BaseTest): self._assert_no_output(cap) self.assert_drag_data_complete(cap) # Verify the empty file was actually created on disk - import os path = dnd_test_probe_state(cap.window_id, 'drag_remote_item_path:0') self.assertIsNotNone(path, 'empty file path should be known') self.assertTrue(os.path.isfile(path), f'empty file must exist on disk: {path}') @@ -2965,7 +2965,6 @@ class TestDnDProtocol(BaseTest): self._assert_no_output(cap) self.assert_drag_data_complete(cap) # Verify the empty child file was actually created on disk - import os dir_path = dnd_test_probe_state(cap.window_id, 'drag_remote_item_path:0') self.assertIsNotNone(dir_path, 'dir path should be known') child_path = os.path.join(dir_path, 'empty_child.txt')