summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2017-09-13 12:45:10 +0300
committerPanu Matilainen <pmatilai@redhat.com>2017-10-26 10:40:47 +0300
commit8bc271482ddfd4bf1e12437e71f208be7884f927 (patch)
tree0238617af991f39b2b0086057c7409717bfa4b20
parente7f67faeb7bdab4f0a4d93f7fda94c77899e1a76 (diff)
downloadrpm-8bc271482ddfd4bf1e12437e71f208be7884f927.tar.gz
Fix file triggers failing to match on some packages (MgBug:18797)
Directory names as stored in RPMTAG_DIRNAMES are not sorted when separated from basenames, so binary search has no chance of working. While a linear search on the dirnames would be guaranteed to find *some* matches when they exist, it could still miss some results as the matches are not guaranteed to exist in a neat low-high range. Construct the entire pathname for prefix comparisons to ensure sorted paths and adjust the file trigger testcase to cover this too. Thanks to Pascal Terjan for initial investigations and Thierry Vignaud for providing a workable reproducer. (cherry picked from commit e760730738a2383f3ab2d558a3f2bff9d4450044)
-rw-r--r--lib/rpmfi.c9
-rw-r--r--tests/data/SPECS/hello-script.spec2
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
index 202b4b3ef..2a5cb56d8 100644
--- a/lib/rpmfi.c
+++ b/lib/rpmfi.c
@@ -480,10 +480,17 @@ int rpmfiFindOFN(rpmfi fi, const char * fn)
return ix;
}
+/*
+ * Dirnames are not sorted when separated from basenames, we need to assemble
+ * the whole path for search (binary or otherwise) purposes.
+ */
static int cmpPfx(rpmfiles files, int ix, const char *pfx)
{
+ char *fn = rpmfilesFN(files, ix);
int plen = strlen(pfx);
- return strncmp(pfx, rpmfilesDN(files, rpmfilesDI(files, ix)), plen);
+ int rc = strncmp(pfx, fn, plen);
+ free(fn);
+ return rc;
}
rpmfileAttrs rpmfilesFFlags(rpmfiles fi, int ix)
diff --git a/tests/data/SPECS/hello-script.spec b/tests/data/SPECS/hello-script.spec
index 567519e33..a28c446f6 100644
--- a/tests/data/SPECS/hello-script.spec
+++ b/tests/data/SPECS/hello-script.spec
@@ -13,6 +13,7 @@ BuildArch: noarch
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin
+mkdir -p $RPM_BUILD_ROOT/zoot
cat << EOF > $RPM_BUILD_ROOT/usr/bin/hello
echo "Hello world!"
EOF
@@ -20,3 +21,4 @@ EOF
%files
%defattr(-,root,root,-)
/usr/bin/hello
+/zoot