[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
wilder-5.22
Jonas Lundholm Bertelsen 5 years ago
parent 1abf7a155d
commit 10780187f5
  1. 24
      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

Loading…
Cancel
Save