Skip to content

Commit ebed52c

Browse files
tintou1ace
authored andcommitted
zink: Return early if the file descriptor could not have been duplicated/acquired
Do not continue and call drmIoctl on an invalid file descriptor. Fix defect reported by Coverity Scan. Argument cannot be negative The negative argument will be interpreted as a very large unsigned value. CID: 1544377 Cc: mesa-stable Signed-off-by: Corentin Noël <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27788> (cherry picked from commit b6962bb)
1 parent 63ab36f commit ebed52c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.pick_status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@
14441444
"description": "zink: Return early if the file descriptor could not have been duplicated/acquired",
14451445
"nominated": true,
14461446
"nomination_type": 0,
1447-
"resolution": 0,
1447+
"resolution": 1,
14481448
"main_sha": null,
14491449
"because_sha": null,
14501450
"notes": null

src/gallium/drivers/zink/zink_screen.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ zink_screen_export_dmabuf_semaphore(struct zink_screen *screen, struct zink_reso
22772277
.fd = -1,
22782278
};
22792279

2280-
int fd;
2280+
int fd = -1;
22812281
if (res->obj->is_aux) {
22822282
fd = os_dupfd_cloexec(res->obj->handle);
22832283
} else {
@@ -2288,6 +2288,11 @@ zink_screen_export_dmabuf_semaphore(struct zink_screen *screen, struct zink_reso
22882288
VKSCR(GetMemoryFdKHR)(screen->dev, &fd_info, &fd);
22892289
}
22902290

2291+
if (unlikely(fd < 0)) {
2292+
mesa_loge("MESA: Unable to get a valid memory fd");
2293+
return VK_NULL_HANDLE;
2294+
}
2295+
22912296
int ret = drmIoctl(fd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &export);
22922297
if (ret) {
22932298
if (errno == ENOTTY || errno == EBADF || errno == ENOSYS) {

0 commit comments

Comments
 (0)