pull in upstream fix for sanitized user environment (#1754395)
parent
428be718dc
commit
04515cb09c
@ -0,0 +1,68 @@
|
|||||||
|
From 10780187f57ab6e68fa08386321f2d0274b951df Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jonas Lundholm Bertelsen <drixi.b@gmail.com>
|
||||||
|
Date: Wed, 13 Jan 2021 01:29:44 +0100
|
||||||
|
Subject: [PATCH 416/419] [libkworkspace] Only update env vars with
|
||||||
|
alphanumeric_ names
|
||||||
|
|
||||||
|
It gives issues with systemd to try and pass it env var names with eg.
|
||||||
|
'%' in them. That to such a degree that if invalid names are passed,
|
||||||
|
none are set [1]. This change ensures compatibility by skipping any
|
||||||
|
non-alphanumerical (and _) variable names.
|
||||||
|
|
||||||
|
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1754395
|
||||||
|
---
|
||||||
|
libkworkspace/updatelaunchenvjob.cpp | 24 ++++++++++++++++++++++++
|
||||||
|
1 file changed, 24 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/libkworkspace/updatelaunchenvjob.cpp b/libkworkspace/updatelaunchenvjob.cpp
|
||||||
|
index f01a4c144..b7e124c71 100644
|
||||||
|
--- a/libkworkspace/updatelaunchenvjob.cpp
|
||||||
|
+++ b/libkworkspace/updatelaunchenvjob.cpp
|
||||||
|
@@ -28,6 +28,7 @@ public:
|
||||||
|
explicit Private(UpdateLaunchEnvJob *q);
|
||||||
|
void monitorReply(const QDBusPendingReply<> &reply);
|
||||||
|
|
||||||
|
+ static bool isPosixName(const QString &name);
|
||||||
|
static bool isSystemdApprovedValue(const QString &value);
|
||||||
|
|
||||||
|
UpdateLaunchEnvJob *q;
|
||||||
|
@@ -82,6 +83,10 @@ void UpdateLaunchEnvJob::start()
|
||||||
|
QStringList systemdUpdates;
|
||||||
|
|
||||||
|
for (const auto &varName : d->environment.keys()) {
|
||||||
|
+ if (!Private::isPosixName(varName)){
|
||||||
|
+ qWarning() << "Skipping syncing of environment variable " << varName << "as name contains unsupported characters";
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
const QString value = d->environment.value(varName);
|
||||||
|
|
||||||
|
// KLauncher
|
||||||
|
@@ -136,6 +141,25 @@ void UpdateLaunchEnvJob::start()
|
||||||
|
d->monitorReply(systemdActivationReply);
|
||||||
|
}
|
||||||
|
|
||||||
|
+bool UpdateLaunchEnvJob::Private::isPosixName(const QString &name)
|
||||||
|
+{
|
||||||
|
+ // Posix says characters like % should be 'tolerated', but it gives issues in practice.
|
||||||
|
+ // https://bugzilla.redhat.com/show_bug.cgi?id=1754395
|
||||||
|
+ // https://bugzilla.redhat.com/show_bug.cgi?id=1879216
|
||||||
|
+ // Ensure systemd compat by only allowing alphanumerics and _ in names.
|
||||||
|
+ bool first = true;
|
||||||
|
+ for (const QChar c : name) {
|
||||||
|
+ if (first && !c.isLetter() && c != QChar('_')) {
|
||||||
|
+ return false;
|
||||||
|
+ } else if (first) {
|
||||||
|
+ first = false;
|
||||||
|
+ } else if (!c.isLetterOrNumber() && c != QChar('_')) {
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return !first;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
bool UpdateLaunchEnvJob::Private::isSystemdApprovedValue(const QString &value)
|
||||||
|
{
|
||||||
|
// systemd code checks that a value contains no control characters except \n \t
|
||||||
|
--
|
||||||
|
2.29.2
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
diff -r -U3 plasma-workspace-5.18.4.1.orig/startkde/startplasma.cpp plasma-workspace-5.18.4.1/startkde/startplasma.cpp
|
|
||||||
--- plasma-workspace-5.18.4.1.orig/startkde/startplasma.cpp 2020-03-31 17:33:37.000000000 +0300
|
|
||||||
+++ plasma-workspace-5.18.4.1/startkde/startplasma.cpp 2020-04-03 20:43:32.178541309 +0300
|
|
||||||
@@ -28,6 +28,9 @@
|
|
||||||
#include <QDBusConnectionInterface>
|
|
||||||
#include <QDBusServiceWatcher>
|
|
||||||
|
|
||||||
+#include <QRegularExpression>
|
|
||||||
+#include <QProcessEnvironment>
|
|
||||||
+
|
|
||||||
#include <KConfig>
|
|
||||||
#include <KConfigGroup>
|
|
||||||
|
|
||||||
@@ -64,8 +66,26 @@
|
|
||||||
int runSync(const QString& program, const QStringList &args, const QStringList &env)
|
|
||||||
{
|
|
||||||
QProcess p;
|
|
||||||
- if (!env.isEmpty())
|
|
||||||
- p.setEnvironment(QProcess::systemEnvironment() << env);
|
|
||||||
+ auto pEnv = QProcessEnvironment::systemEnvironment();
|
|
||||||
+ if (!env.isEmpty()) {
|
|
||||||
+ for (const auto &value : env) {
|
|
||||||
+ int pos = value.indexOf(QStringLiteral("="));
|
|
||||||
+ if (pos != -1) {
|
|
||||||
+ pEnv.insert(value.left(pos), value.mid(pos+1));
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ if (program.endsWith(QStringLiteral("dbus-update-activation-environment"))) {
|
|
||||||
+ const QRegularExpression re(QStringLiteral("[^A-Z0-9_]"));
|
|
||||||
+ for (const auto &key : pEnv.keys()) {
|
|
||||||
+ const auto match = re.match(key);
|
|
||||||
+ if (match.hasMatch()) {
|
|
||||||
+ pEnv.remove(key);
|
|
||||||
+ qInfo() << "program:" << program << "environment variable removed:" << key;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ p.setProcessEnvironment(pEnv);
|
|
||||||
p.setProcessChannelMode(QProcess::ForwardedChannels);
|
|
||||||
p.start(program, args);
|
|
||||||
// qDebug() << "started..." << program << args;
|
|
Loading…
Reference in new issue