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
16 changes: 8 additions & 8 deletions src/plugin-qt/xsettings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
set(BIN_NAME "dde-xsettings")
set(BIN_NAME "plugin-dde-xsettings")

project(${BIN_NAME})

Expand All @@ -19,7 +19,7 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb)

add_executable(${BIN_NAME}
add_library(${BIN_NAME} MODULE
${SRCS}
)

Expand All @@ -36,12 +36,12 @@ macro(install_user_symlink filepath wantsdir)
install(FILES ${PROJECT_BINARY_DIR}/link/${wantsdir}/${filepath} DESTINATION lib/systemd/user/${wantsdir}/)
endmacro(install_user_symlink)

install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/dde-xsettings.json DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/deepin-service-manager/other)
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager/)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/plugin-dde-xsettings.json DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/deepin-service-manager/user)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/org.deepin.XSettings.json DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dsg/configs/org.deepin.dde.daemon)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/dbus/org.deepin.dde.XSettings.service DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/services)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/org.deepin.dde.XSettings.service
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/dbus/org.deepin.dde.XSettings1.service DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/services)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/org.deepin.dde.XSettings1.service
DESTINATION lib/systemd/user/
RENAME org.deepin.dde.XSettings.service
RENAME org.deepin.dde.XSettings1.service
)
install_user_symlink(org.deepin.dde.XSettings.service dde-session-pre.target.wants)
install_user_symlink(org.deepin.dde.XSettings1.service dde-session-pre.target.wants)
28 changes: 0 additions & 28 deletions src/plugin-qt/xsettings/main.cpp

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.deepin.dde.XSettings1
Exec=/usr/bin/deepin-service-manager -n org.deepin.dde.XSettings1
SystemdService=org.deepin.dde.XSettings1.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=dde-xsettings
Description=org.deepin.dde.XSettings1
Requisite=dde-session-initialized.target dde-session-pre.target
RefuseManualStart=no
RefuseManualStop=no
Expand All @@ -13,7 +13,7 @@ Before=dde-session@x11.service
[Service]
Type=dbus
BusName=org.deepin.dde.XSettings1
ExecStart=/usr/bin/dde-xsettings
ExecStart=/usr/bin/deepin-service-manager -n org.deepin.dde.XSettings1
Restart=on-failure
RestartSec=3
Slice=session.slice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "org.deepin.dde.XSettings1",
"libPath": "libplugin-dde-xsettings.so",
"startType": "Resident",
"pluginType": "qt",
"policy": [
{
"path": "/org/deepin/dde/XSettings1"
Expand Down
40 changes: 40 additions & 0 deletions src/plugin-qt/xsettings/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "impl/xsettings1.h"

#include <QDBusConnection>

Check warning on line 7 in src/plugin-qt/xsettings/plugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 8 in src/plugin-qt/xsettings/plugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

static XSettings1 *xSettings = nullptr;

extern "C" int DSMRegister(const char *name, void *data)
{

auto connection = reinterpret_cast<QDBusConnection *>(data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Defensive checks for data/connection before use would avoid undefined behavior.

Here we reinterpret_cast and immediately call connection->interface() without validating data or the interface pointer. If DSMRegister is ever invoked with a null or unexpected data, this will dereference a null pointer and crash. Please add guards, e.g.:

if (!data)
    return 1;

auto connection = reinterpret_cast<QDBusConnection *>(data);
if (!connection || !connection->interface())
    return 1;

Optionally log a warning so these failures are diagnosable.

if (connection->interface()->isServiceRegistered(name)) {
qWarning() << "DBus service already exists:" << name;
return 1;
}
xSettings = new XSettings1();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Guard against multiple DSMRegister calls to avoid leaking/reusing the global instance.

A second DSMRegister call would overwrite the global xSettings without deleting the previous instance, leaking it and possibly leaving it registered on DBus. Please add a guard, e.g.:

if (xSettings) {
    qWarning() << "XSettings1 already instantiated";
    return 1;
}

before allocating to make the singleton’s lifecycle explicit and prevent misuse.


QDBusConnection::RegisterOptions opts = QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllProperties;
QString path = name;
path = QString("/%1").arg(path.replace(".", "/"));
connection->registerObject(path, xSettings, opts);
return 0;
}

// 该函数用于资源释放
// 非常驻插件必须实现该函数,以防内存泄漏
extern "C" int DSMUnRegister(const char *name, void *data)
{
Q_UNUSED(name);
Q_UNUSED(data);
if (xSettings) {
xSettings->deleteLater();
xSettings = nullptr;
}
return 0;
}