Skip to content

util/envlist: fix prefix-match in name lookup

Denis V. Lunev via qemu development qemu-devel 1 version Applied

Status from this message: Thanks, applied to staging:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/2util/envlist: fix prefix-match in envlist_unsetenv() name lookuputil/envlist.c+15 -40 replies
2/2tests/unit: add test-envlist covering setenv/unsetenv name matchingtests/unit/meson.build tests/unit/test-envlist.c+197 -00 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchStefan Hajnoczi
SeriesR-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] util/envlist: fix prefix-match in name lookup

A bug report against our downstream tree turned out to have its root cause in plain mainstream code: envlist_unsetenv() does a prefix-match lookup that drops the wrong entry when one stored name happens to be a prefix of another. The downstream symptom is specific to our setup and isn't interesting here -- the underlying lookup mistake is the part worth fixing, and it is reachable from a normal qemu-user invocation through the -U command-line option, so the fix belongs upstream.

Patch 1 fixes the lookup: each entry now stores its name length at insertion time, and a tiny helper compares with explicit length equality plus memcmp. envlist_setenv()'s self-search was accidentally safe (it included the '=' byte in its strncmp window and that '=' served as a boundary) but is converted to the same helper so the name boundary becomes a structural property of the entry rather than a property of its byte layout. Without that, the two sites can easily drift apart again.

Patch 2 backfils test coverage for util/envlist -- there was none -- in tests/unit/test-envlist. I verified that the regression case (envlist_unsetenv("FOO") vs. a stored "FOOBAR=...") fails against the pre-fix code and passes after the fix.

Cc Stefan Hajnoczi <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Paolo Bonzini <[email protected]>

Denis V. Lunev (2):
util/envlist: fix prefix-match in envlist_unsetenv() name lookup tests/unit: add test-envlist covering setenv/unsetenv name matching

 tests/unit/meson.build    |   1 +
 tests/unit/test-envlist.c | 196 ++++++++++++++++++++++++++++++++++++++
 util/envlist.c            |  19 +++-
 3 files changed, 212 insertions(+), 4 deletions(-)
 create mode 100644 tests/unit/test-envlist.c
Signature · 1 line
2.51.0