From 0b56a8567d6c955ffbee6c98969ec41a3946ba9a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 18 May 2026 08:37:50 +0530 Subject: [PATCH] Use O_EXCL with O_CREAT for drag source files --- kitty/dnd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kitty/dnd.c b/kitty/dnd.c index 11342cf50..942420794 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -2085,7 +2085,7 @@ add_payload(Window *w, DragRemoteItem *ri, bool has_more, const uint8_t *payload switch (ri->type) { case 0: { if (!ri->fd_plus_one) { - int fd = safe_openat(dirfd, ri->dir_entry_name, O_CREAT | O_WRONLY, file_permissions); + int fd = safe_openat(dirfd, ri->dir_entry_name, O_CREAT | O_WRONLY | O_EXCL, file_permissions); if (fd < 0) abrt(errno, "could not open drag source item data file"); ri->fd_plus_one = fd + 1; } @@ -2121,7 +2121,7 @@ add_payload(Window *w, DragRemoteItem *ri, bool has_more, const uint8_t *payload } else { // Empty file: no data payload was ever received so the file was never opened; // create it now so that it exists at the expected path for the caller. - int fd = safe_openat(dirfd, ri->dir_entry_name, O_CREAT | O_WRONLY, file_permissions); + int fd = safe_openat(dirfd, ri->dir_entry_name, O_CREAT | O_WRONLY | O_EXCL, file_permissions); if (fd < 0) abrt(errno, "could not create empty drag source item file"); safe_close(fd, __FILE__, __LINE__); }