fix: unescape exec before pass this arg to wordexp

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-10-19 14:18:44 +08:00
committed by Comix
parent 5597ba5c44
commit f796535233
5 changed files with 98 additions and 27 deletions

View File

@ -9,6 +9,7 @@
#include "propertiesForwarder.h"
#include "dbus/instanceadaptor.h"
#include "launchoptions.h"
#include "desktopentry.h"
#include <QUuid>
#include <QStringList>
#include <QList>
@ -197,7 +198,8 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
sendErrorReply(QDBusError::Failed, msg);
return {};
}
execStr = toString(Actions.value());
execStr = Actions.value().toString();
if (execStr.isEmpty()) {
QString msg{"maybe entry actions's format is invalid, abort launch."};
qWarning() << msg;
@ -733,13 +735,21 @@ void ApplicationService::resetEntry(DesktopEntry *newEntry) noexcept
emit scaleFactorChanged();
}
LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringList &fields)
QStringList ApplicationService::unescapeExecArgs(const QString &str) noexcept
{
LaunchTask task;
auto deleter = [](wordexp_t *word) { wordfree(word); };
auto unescapedStr = unescape(str, true);
if (unescapedStr.isEmpty()) {
qWarning() << "unescape Exec failed.";
return {};
}
auto deleter = [](wordexp_t *word) {
wordfree(word);
delete word;
};
std::unique_ptr<wordexp_t, decltype(deleter)> words{new (std::nothrow) wordexp_t{0, nullptr, 0}, deleter};
if (auto ret = wordexp(str.toLocal8Bit().constData(), words.get(), WRDE_SHOWERR); ret != 0) {
if (auto ret = wordexp(unescapedStr.toLocal8Bit(), words.get(), WRDE_SHOWERR); ret != 0) {
if (ret != 0) {
QString errMessage;
switch (ret) {
@ -771,6 +781,14 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis
for (int i = 0; i < words->we_wordc; ++i) {
execList.emplace_back(words->we_wordv[i]);
}
return execList;
}
LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringList &fields) noexcept
{
LaunchTask task;
auto execList = unescapeExecArgs(str);
task.LaunchBin = execList.first();
QRegularExpression re{"%[fFuUickdDnNvm]"};

View File

@ -5,25 +5,25 @@
#ifndef APPLICATIONSERVICE_H
#define APPLICATIONSERVICE_H
#include <QObject>
#include <QDBusObjectPath>
#include <QMap>
#include <QString>
#include <QDBusUnixFileDescriptor>
#include <QSharedPointer>
#include <QUuid>
#include <QTextStream>
#include <QDBusContext>
#include <QFile>
#include <memory>
#include <utility>
#include "applicationmanager1service.h"
#include "applicationmanagerstorage.h"
#include "dbus/applicationmanager1service.h"
#include "dbus/instanceservice.h"
#include "global.h"
#include "desktopentry.h"
#include "dbus/jobmanager1service.h"
#include "applicationmanager1service.h"
#include "desktopentry.h"
#include "global.h"
#include <QDBusContext>
#include <QDBusObjectPath>
#include <QDBusUnixFileDescriptor>
#include <QFile>
#include <QMap>
#include <QObject>
#include <QSharedPointer>
#include <QString>
#include <QTextStream>
#include <QUuid>
#include <memory>
#include <utility>
QString getDeepinWineScaleFactor(const QString &appId) noexcept;
double getScaleFactor() noexcept;
@ -70,8 +70,8 @@ public:
[[nodiscard]] bool terminal() const noexcept;
// FIXME:
// This property should implement with fuse guarded $XDG_CONFIG_HOME/autostart/.
// Current implementation has some problems,
// This property should implement with fuse guarded
// $XDG_CONFIG_HOME/autostart/. Current implementation has some problems,
Q_PROPERTY(bool AutoStart READ isAutoStart WRITE setAutoStart NOTIFY autostartChanged)
[[nodiscard]] bool isAutoStart() const noexcept;
void setAutoStart(bool autostart) noexcept;
@ -119,6 +119,9 @@ public:
void resetEntry(DesktopEntry *newEntry) noexcept;
void detachAllInstance() noexcept;
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields) noexcept;
[[nodiscard]] static QStringList unescapeExecArgs(const QString &str) noexcept;
private Q_SLOTS:
void onGlobalScaleFactorChanged() noexcept;
@ -165,7 +168,6 @@ private:
DesktopFile m_desktopSource;
QSharedPointer<DesktopEntry> m_entry{nullptr};
QMap<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields);
[[nodiscard]] QVariant findEntryValue(const QString &group,
const QString &valueKey,
EntryValueType type,