Skip to content

Commit

Permalink
Fix heap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jul 27, 2023
1 parent 6d5e324 commit 9440c69
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
75 changes: 15 additions & 60 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,14 @@ void Application::launchNoSecurityCheck(){
if(m_process->processId()){
resumeNoSecurityCheck();
}else{

Check notice on line 115 in applications/system-service/application.cpp

View check run for this annotation

codefactor.io / CodeFactor

applications/system-service/application.cpp#L24-L115

Complex Method
auto name = this->name().toStdString();
if(sharedSettings.applicationUsage()){
transaction = Oxide::Sentry::start_transaction("application", "run");
#ifdef SENTRY
if(transaction != nullptr){
sentry_transaction_set_tag(transaction->inner, "application", name().toStdString().c_str());
}
#endif
Oxide::Sentry::set_tag(transaction, "application", name);
startSpan("starting", "Application is starting");
}
Oxide::Sentry::sentry_transaction("application", "launch", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::sentry_transaction("application", "launch", [this, name](Oxide::Sentry::Transaction* t){
Oxide::Sentry::set_tag(t, "application", name);
appsAPI->recordPreviousApplication();
O_INFO("Launching " << path().toStdString().c_str());
appsAPI->pauseAll();
Expand All @@ -150,7 +141,7 @@ void Application::launchNoSecurityCheck(){
m_process->closeReadChannel(QProcess::StandardOutput);
}else{
if(p_stdout == nullptr){
p_stdout_fd = sd_journal_stream_fd(name().toStdString().c_str(), LOG_INFO, 1);
p_stdout_fd = sd_journal_stream_fd(name.c_str(), LOG_INFO, 1);
if (p_stdout_fd < 0) {
errno = -p_stdout_fd;
O_INFO("Failed to create stdout fd:" << -p_stdout_fd);
Expand All @@ -161,12 +152,12 @@ void Application::launchNoSecurityCheck(){
close(p_stdout_fd);
}else{
p_stdout = new QTextStream(log);
O_INFO("Opened stdout for " << name().toStdString().c_str());
O_INFO("Opened stdout for " << name.c_str());
}
}
}
if(p_stderr == nullptr){
p_stderr_fd = sd_journal_stream_fd(name().toStdString().c_str(), LOG_ERR, 1);
p_stderr_fd = sd_journal_stream_fd(name.c_str(), LOG_ERR, 1);
if (p_stderr_fd < 0) {
errno = -p_stderr_fd;
O_INFO("Failed to create sterr fd:" << -p_stderr_fd);
Expand All @@ -177,7 +168,7 @@ void Application::launchNoSecurityCheck(){
close(p_stderr_fd);
}else{
p_stderr = new QTextStream(log);
O_INFO("Opened stderr for " << name().toStdString().c_str());
O_INFO("Opened stderr for " << name.c_str());
}
}
}
Expand Down Expand Up @@ -215,13 +206,7 @@ void Application::pauseNoSecurityCheck(bool startIfNone){
}
O_INFO("Pausing " << path());
Oxide::Sentry::sentry_transaction("application", "pause", [this, startIfNone](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
interruptApplication();
if(startIfNone){
appsAPI->resumeIfNone();
Expand All @@ -240,13 +225,7 @@ void Application::interruptApplication(){
return;
}
Oxide::Sentry::sentry_transaction("application", "interrupt", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
if(environment().contains("OXIDE_PRELOAD_EXPOSE_FB")){
saveScreen();
}
Expand Down Expand Up @@ -326,13 +305,7 @@ void Application::resumeNoSecurityCheck(){
return;
}
Oxide::Sentry::sentry_transaction("application", "resume", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
appsAPI->recordPreviousApplication();
O_INFO("Resuming " << path());
appsAPI->pauseAll();
Expand All @@ -353,13 +326,7 @@ void Application::uninterruptApplication(){
return;
}
Oxide::Sentry::sentry_transaction("application", "uninterrupt", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
if(environment().contains("OXIDE_PRELOAD_EXPOSE_FB")){
recallScreen();
}
Expand Down Expand Up @@ -413,13 +380,7 @@ void Application::stopNoSecurityCheck(){
return;
}
Oxide::Sentry::sentry_transaction("application", "stop", [this, state](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
O_INFO("Stopping " << path());
if(!onStop().isEmpty()){
Oxide::Sentry::sentry_span(t, "onStop", "Run onStop action", [this](){
Expand Down Expand Up @@ -491,7 +452,7 @@ void Application::unregisterNoSecurityCheck(){
appsAPI->unregisterApplication(this);
}

QString Application::name() { return value("name").toString(); }
QString Application::name() { return value("name", path()).toString(); }

int Application::processId() { return m_process->processId(); }

Expand Down Expand Up @@ -867,13 +828,7 @@ void Application::updateEnvironment(){

void Application::showSplashScreen(){
Oxide::Sentry::sentry_transaction("application", "showSplashScreen", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::set_tag(t, "application", name().toStdString());
O_INFO("Displaying splashscreen for" << name());
Oxide::Sentry::sentry_span(t, "paint", "Draw splash screen", [this](){
auto image = AppsAPI::_window()->toImage();
Expand Down
11 changes: 11 additions & 0 deletions qmake/common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ DEFINES += QT_DEPRECATED_WARNINGS
!contains(DEFINES, QT_DISABLE_DEPRECATED_BEFORE){
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x051510
}
CONFIG(debug, debug|release){
QMAKE_LFLAGS += -fno-omit-frame-pointer
QMAKE_LFLAGS += -fsanitize-recover=address

QMAKE_LFLAGS += -fsanitize=address
QMAKE_LFLAGS += -fsanitize=leak
# QMAKE_LFLAGS += -fsanitize=thread # Incompatible with address and leak
QMAKE_LFLAGS += -fsanitize=undefined
QMAKE_LFLAGS += -fsanitize=pointer-compare
QMAKE_LFLAGS += -fsanitize=pointer-subtract
}

QMAKE_RPATHDIR += /lib /usr/lib /opt/lib /opt/usr/lib
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
Expand Down
5 changes: 5 additions & 0 deletions shared/liboxide/liboxide_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
# define DEBUG
# define LIBOXIDE_EXPORT
#endif
#if defined(__clang__) || defined (__GNUC__)
# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#else
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
#endif
/*! @} */
10 changes: 10 additions & 0 deletions shared/liboxide/oxide_sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ namespace Oxide::Sentry{
auto scopeGuard = qScopeGuard([transaction] {
stop_transaction(transaction);
});
Q_UNUSED(scopeGuard);
callback(transaction);
#else
Q_UNUSED(name);
Expand Down Expand Up @@ -318,6 +319,7 @@ namespace Oxide::Sentry{
auto scopeGuard = qScopeGuard([span] {
stop_span(span);
});
Q_UNUSED(scopeGuard);
callback(span);
#else
Q_UNUSED(transaction);
Expand Down Expand Up @@ -350,6 +352,7 @@ namespace Oxide::Sentry{
auto scopeGuard = qScopeGuard([span] {
stop_span(span);
});
Q_UNUSED(scopeGuard);
callback(span);
#else
Q_UNUSED(parent);
Expand All @@ -359,4 +362,11 @@ namespace Oxide::Sentry{
#endif
}
void trigger_crash(){ memset((char *)invalid_mem, 1, 100); }

void set_tag(Transaction* transaction, const std::string& name, const std::string& tag){
#ifdef SENTRY
sentry_transaction_set_tag_n(transaction->inner, name.c_str(), name.size(), tag.c_str(), tag.size());
#endif
}

}
9 changes: 9 additions & 0 deletions shared/liboxide/oxide_sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,14 @@ namespace Oxide::Sentry{
* \brief Trigger a crash. Useful to test that sentry integration is working
*/
LIBOXIDE_EXPORT void trigger_crash();
/*!
* \brief Set a tag on a transaction
* \param The transaction to set the tag on
* \param name The name of the tag
* \param tag The tag value
*/
LIBOXIDE_EXPORT
ATTRIBUTE_NO_SANITIZE_ADDRESS
void set_tag(Transaction* transaction, const std::string& name, const std::string& tag);
}
/*! @} */
11 changes: 8 additions & 3 deletions shared/qpa/oxideintegration.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "oxideintegration.h"
#include "oxidebackingstore.h"
#include "oxidescreen.h"
#include "oxideeventfilter.h"
#include "oxideeventhandler.h"

#include <QtGui/private/qguiapplication_p.h>
Expand Down Expand Up @@ -98,7 +97,8 @@ void OxideIntegration::initialize(){
O_DEBUG(socket->readAll());
}
});
qApp->installEventFilter(new OxideEventFilter(qApp));
m_eventFilter = new OxideEventFilter(qApp);
qApp->installEventFilter(m_eventFilter);
m_inputContext = QPlatformInputContextFactory::create();
auto eventPipe = Oxide::Tarnish::getEventPipe();
if(eventPipe == nullptr){
Expand All @@ -109,14 +109,19 @@ void OxideIntegration::initialize(){
qApp->exit(EXIT_FAILURE);
}
});
new OxideEventHandler(eventPipe, m_primaryScreen);
m_eventHandler = new OxideEventHandler(eventPipe, m_primaryScreen);
connectSignal(signalHandler, "sigCont()", m_primaryScreen, "raiseTopWindow()");
connectSignal(signalHandler, "sigUsr1()", m_primaryScreen, "raiseTopWindow()");
connectSignal(signalHandler, "sigUsr2()", m_primaryScreen, "lowerTopWindow()");
connectSignal(signalHandler, "sigTerm()", m_primaryScreen, "closeTopWindow()");
connectSignal(signalHandler, "sigInt()", m_primaryScreen, "closeTopWindow()");
}

void OxideIntegration::destroy(){
qApp->removeEventFilter(m_eventFilter);
Oxide::Tarnish::disconnect();
}


// Dummy font database that does not scan the fonts directory to be
// used for command line tools like qmlplugindump that do not create windows
Expand Down
5 changes: 5 additions & 0 deletions shared/qpa/oxideintegration.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "oxidescreen.h"
#include "oxidewindow.h"
#include "oxideeventfilter.h"
#include "oxideeventhandler.h"

#include <qpa/qplatformintegration.h>
#include <qpa/qplatformnativeinterface.h>
Expand All @@ -26,6 +28,7 @@ class Q_DECL_EXPORT OxideIntegration : public QPlatformIntegration, public QPlat

bool hasCapability(QPlatformIntegration::Capability cap) const override;
void initialize() override;
void destroy() override;
QPlatformFontDatabase* fontDatabase() const override;
QPlatformInputContext* inputContext() const override;
QPlatformWindow* createPlatformWindow(QWindow* window) const override;
Expand All @@ -41,6 +44,8 @@ class Q_DECL_EXPORT OxideIntegration : public QPlatformIntegration, public QPlat
mutable QPlatformFontDatabase* m_fontDatabase;
QPlatformInputContext* m_inputContext;
OxideScreen* m_primaryScreen;
OxideEventFilter* m_eventFilter;
OxideEventHandler* m_eventHandler;
unsigned m_options;
bool m_debug;
QStringList m_spec;
Expand Down

0 comments on commit 9440c69

Please sign in to comment.