effects/screenshot: Fix potentially leaking screenshot fds to child processes

dup() doesn't copy flags such as FD_CLOEXEC.
This commit is contained in:
Vlad Zahorodnii 2023-04-25 09:29:51 +03:00
parent 60dc812b21
commit c2c229fb05

View file

@ -367,7 +367,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureActiveWindow(const QVariantMap &opt
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -403,7 +403,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureWindow(const QString &handle,
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -430,7 +430,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureArea(int x, int y, int width, int h
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -457,7 +457,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureScreen(const QString &name,
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -483,7 +483,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureActiveScreen(const QVariantMap &opt
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -500,7 +500,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureInteractive(uint kind,
const QVariantMap &options,
QDBusUnixFileDescriptor pipe)
{
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
@ -555,7 +555,7 @@ QVariantMap ScreenShotDBusInterface2::CaptureWorkspace(const QVariantMap &option
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
const int fileDescriptor = fcntl(pipe.fileDescriptor(), F_DUPFD_CLOEXEC, 0);
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();