Files
qemu/util
Denis V. Lunev 69a43064dc util/envlist: fix prefix-match in envlist_unsetenv() name lookup
envlist_unsetenv() looked up the entry to remove with
strncmp(entry->ev_var, env, strlen(env)). The comparison length is
the requested name's length, so any stored entry whose name *starts*
with that name compares equal. envlist_setenv() inserts at the head
of the list, so the first hit wins: with FOO=... stored first and
FOOBAR=... stored afterward, envlist_unsetenv("FOO") iterates from
the head, matches FOOBAR=... on the prefix, and drops it instead of
FOO=...

linux-user and bsd-user reach this code via the -U command-line
switch, so the bug is reachable from a normal qemu-user invocation.

envlist_setenv() used the same strncmp pattern but with
envname_len = (eq_sign - env + 1), so the '=' byte sat inside the
compared window and acted as an implicit boundary. setenv was
therefore not buggy -- but the safety lived in the byte layout of
ev_var rather than in the entry, so a future edit could easily
drift the two sites apart again.

Store the name length on each entry at insertion time and compare
with explicit length equality plus memcmp via a small helper. Use
the helper at both lookup sites so the boundary becomes a
structural property of the entry: envlist_unsetenv() stops
prefix-matching, and envlist_setenv()'s self-search no longer
depends on the '=' byte serving as a sentinel.

Fixes: 04a6dfebb6 ("linux-user: Add generic env variable handling")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20260520212628.479772-2-den@openvz.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit c131ae56c1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-06-04 22:56:55 +03:00
..
2023-03-20 12:43:50 +01:00
2023-12-19 19:03:38 +01:00
2025-01-16 20:57:17 -08:00
2023-05-23 15:20:15 +08:00
2020-01-06 18:41:32 +04:00
2024-09-13 20:11:13 +02:00
2025-03-04 14:45:34 +01:00
2025-03-10 17:07:16 +08:00
2024-12-20 17:44:56 +01:00
2025-01-29 11:43:04 -03:00
2023-04-24 11:29:00 +02:00
2020-12-10 17:16:44 +01:00
2024-06-21 09:47:22 -03:00
2023-08-31 19:47:43 +02:00
2022-06-29 10:56:12 +03:00
2018-12-20 10:29:08 +01:00
2023-02-02 11:48:20 +00:00
2023-03-28 15:23:10 -07:00
2023-11-15 12:06:05 +03:00
2023-04-27 16:39:43 +02:00
2018-08-24 20:26:37 +02:00
2023-11-03 09:20:31 +01:00