Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/dde-update/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>

Check warning on line 24 in src/dde-update/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <poll.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cerrno>

Check warning on line 25 in src/dde-update/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cerrno> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstring>

Check warning on line 26 in src/dde-update/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstring> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sys/stat.h>

Check warning on line 27 in src/dde-update/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/stat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Q_LOGGING_CATEGORY(logUpdateModal, "dde.update.modalupdate")

Expand Down Expand Up @@ -86,12 +87,20 @@
if (m_path.isEmpty()) {
return;
}
// Write our PID so the wrapper can track this exact process via kill -0.
// Open first, then verify it's a FIFO via fstat().
// This avoids the TOCTOU race of stat() before open().
int fd = open(m_path.toUtf8().constData(), O_WRONLY | O_NONBLOCK);
if (fd < 0) {
qCWarning(logUpdateModal) << "FifoNotifier: cannot report PID, open failed:" << strerror(errno);
return;
}
struct stat st;
if (fstat(fd, &st) != 0 || !S_ISFIFO(st.st_mode)) {
qCWarning(logUpdateModal) << "FifoNotifier: path is not a FIFO, cannot report PID";
close(fd);
return;
}
// Write our PID so the wrapper can track this exact process via kill -0.
QByteArray msg = "PID:" + QByteArray::number(getpid()) + "\n";
bool ok = writeAllFifo(fd, msg, 5000);
close(fd);
Expand All @@ -108,13 +117,21 @@
return;
}
qCInfo(logUpdateModal) << "FifoNotifier: notifying FIFO" << m_path;
// Open first, then verify it's a FIFO via fstat().
// This avoids the TOCTOU race of stat() before open().
// O_NONBLOCK so we don't hang if the reader already closed;
// the script opens fd 3<> before launching us so a reader exists.
int fd = open(m_path.toUtf8().constData(), O_WRONLY | O_NONBLOCK);
if (fd < 0) {
qCWarning(logUpdateModal) << "FifoNotifier: cannot open" << m_path << ":" << strerror(errno);
return;
}
struct stat st;
if (fstat(fd, &st) != 0 || !S_ISFIFO(st.st_mode)) {
qCWarning(logUpdateModal) << "FifoNotifier: path is not a FIFO, cannot notify";
close(fd);
return;
}
// Write "EXIT\n" to signal exit to the wrapper.
QByteArray msg("EXIT\n");
bool ok = writeAllFifo(fd, msg, 2000);
Expand Down
17 changes: 17 additions & 0 deletions src/dde-update/securityloaderhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#include <fcntl.h>
#include <chrono>
#include <cerrno>
#include <cstring>

Check warning on line 18 in src/dde-update/securityloaderhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstring> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstdlib>

Check warning on line 19 in src/dde-update/securityloaderhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstdlib> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <climits>

Check warning on line 20 in src/dde-update/securityloaderhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <climits> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sys/stat.h>

Check warning on line 21 in src/dde-update/securityloaderhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/stat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

static const QString DEFAULT_AUTH_RESOURCE = ":/misc/org.deepin.dde-update.json";
// Upper bound for the authorization response to guard against a misbehaving
Expand Down Expand Up @@ -65,6 +66,14 @@
continue;
}
info.fd1 = static_cast<int>(fd);
// Verify the fd is actually a FIFO to prevent writing
// authorization data to arbitrary open files.
struct stat st;
if (fstat(info.fd1, &st) != 0 || !S_ISFIFO(st.st_mode)) {
qWarning() << "fd1 is not a FIFO, ignoring";
info.fd1 = -1;
continue;
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
}
info.isLoadedByLoader = true;
} else if (strcmp(argv[i], "--fd2") == 0 && i + 1 < argc) {
const char *val = argv[++i];
Expand All @@ -77,6 +86,14 @@
continue;
}
info.fd2 = static_cast<int>(fd);
// Verify the fd is actually a FIFO to prevent writing
// authorization data to arbitrary open files.
struct stat st;
if (fstat(info.fd2, &st) != 0 || !S_ISFIFO(st.st_mode)) {
qWarning() << "fd2 is not a FIFO, ignoring";
info.fd2 = -1;
continue;
}
}
}

Expand Down
Loading