You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
plasma-workspace/0416-libkworkspace-Only-upd...

69 lines
2.5 KiB

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