CmdBridge: Filter out invalid environment entries

For some reason the os.Environ() would include entries like:
` =/tmp/_qtc_cmdbridge`. Those did break the linuxdevice
fullLocalCommandLine().

We now filter them out both in the bridge and the device.

Change-Id: If1ab6b6b762edbc402d095500e91b3689deaed73
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-10-15 09:32:47 +02:00
parent 5c0c8d9e66
commit 9b622a741c
2 changed files with 9 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ import (
"path/filepath"
"reflect"
"runtime"
"slices"
"strings"
"sync"
"syscall"
@@ -402,7 +404,12 @@ func processCommand(watcher *WatcherHandler, cmd command, out chan<- []byte) {
func sendEnvironment(out chan<- []byte) {
env := os.Environ()
// Delete all entries without a valid key.
env := slices.DeleteFunc(os.Environ(), func(s string) bool {
trimmed := strings.TrimSpace(s)
return len(trimmed) == 0 || trimmed[0] == '='
})
result, _ := cbor.Marshal(environment{
Type: "environment",
Id: -1,

View File

@@ -826,7 +826,7 @@ CommandLine SshProcessInterfacePrivate::fullLocalCommandLine() const
const Environment &env = q->m_setup.m_environment;
env.forEachEntry([&](const QString &key, const QString &value, bool enabled) {
if (enabled)
if (enabled && !key.trimmed().isEmpty())
inner.addArgs(key + "='" + env.expandVariables(value) + '\'', CommandLine::Raw);
});