env: skip env lines without equal sign

Given an env like

    foo
    bar=baz

we would set "foo" to empty due to a typo.
The typo is pointed out by a PORTING comment.

Luckily I don't think we ever hit this case because that would mean our
parent process has a serious bug.  Rust's std::env::vars_os() skips env
lines that don't contain a "=" char.  This seems like a reasonable behavior
for us too. Do that.
This commit is contained in:
Johannes Altmanninger
2023-10-07 21:48:28 +02:00
parent e8712af0c3
commit 6ef5ae0935

View File

@@ -175,13 +175,11 @@ void set_inheriteds_ffi() {
const wcstring key_and_val = str2wcstring(envp[i]);
size_t eql = key_and_val.find(L'=');
if (eql == wcstring::npos) {
// PORTING: Should this not be key_and_val?
inheriteds[key] = L"";
} else {
key.assign(key_and_val, 0, eql);
val.assign(key_and_val, eql + 1, wcstring::npos);
inheriteds[key] = val;
continue;
}
key.assign(key_and_val, 0, eql);
val.assign(key_and_val, eql + 1, wcstring::npos);
inheriteds[key] = val;
}
}