Blame SOURCES/0002-build-check-rich-dependencies-for-special-characters.patch

f6faf3
From e7fa1f1c1c4a6161c2254c761e857fdf04fba5ef Mon Sep 17 00:00:00 2001
f6faf3
Message-Id: <e7fa1f1c1c4a6161c2254c761e857fdf04fba5ef.1574338784.git.pmatilai@redhat.com>
f6faf3
In-Reply-To: <871065ddd493c76d80345d2e80b38b9ce4c7acdd.1574338784.git.pmatilai@redhat.com>
f6faf3
References: <871065ddd493c76d80345d2e80b38b9ce4c7acdd.1574338784.git.pmatilai@redhat.com>
f6faf3
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
f6faf3
Date: Wed, 21 Nov 2018 15:36:35 +0100
f6faf3
Subject: [PATCH 2/3] build: check rich dependencies for special characters
f6faf3
f6faf3
Reported-by: Michael Schroeder 
f6faf3
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
f6faf3
---
f6faf3
 build/pack.c | 30 +++++++++++++++++++++++++++---
f6faf3
 1 file changed, 27 insertions(+), 3 deletions(-)
f6faf3
f6faf3
diff --git a/build/pack.c b/build/pack.c
f6faf3
index daf878c76..c94964be2 100644
f6faf3
--- a/build/pack.c
f6faf3
+++ b/build/pack.c
f6faf3
@@ -228,12 +228,36 @@ exit:
f6faf3
     return rc;
f6faf3
 }
f6faf3
 
f6faf3
-static int haveTildeDep(Package pkg)
f6faf3
+struct charInDepData {
f6faf3
+    char c;
f6faf3
+    int present;
f6faf3
+};
f6faf3
+
f6faf3
+static rpmRC charInDepCb(void *cbdata, rpmrichParseType type,
f6faf3
+		const char *n, int nl, const char *e, int el, rpmsenseFlags sense,
f6faf3
+		rpmrichOp op, char **emsg) {
f6faf3
+    struct charInDepData *data = cbdata;
f6faf3
+    if (memchr(e, data->c, el))
f6faf3
+	data->present = 1;
f6faf3
+
f6faf3
+    return RPMRC_OK;
f6faf3
+}
f6faf3
+
f6faf3
+static int haveCharInDep(Package pkg, char c)
f6faf3
 {
f6faf3
+    struct charInDepData data = {c, 0};
f6faf3
     for (int i = 0; i < PACKAGE_NUM_DEPS; i++) {
f6faf3
 	rpmds ds = rpmdsInit(pkg->dependencies[i]);
f6faf3
 	while (rpmdsNext(ds) >= 0) {
f6faf3
-	    if (strchr(rpmdsEVR(ds), '~'))
f6faf3
+	    if (rpmdsIsRich(ds)) {
f6faf3
+		const char *depstr = rpmdsN(ds);
f6faf3
+		rpmrichParse(&depstr, NULL, charInDepCb, &data);
f6faf3
+	    } else {
f6faf3
+		const char *evr = rpmdsEVR(ds);
f6faf3
+		if (strchr(evr, c))
f6faf3
+		    data.present = 1;
f6faf3
+	    }
f6faf3
+	    if (data.present)
f6faf3
 		return 1;
f6faf3
 	}
f6faf3
     }
f6faf3
@@ -327,7 +351,7 @@ exit:
f6faf3
 static void finalizeDeps(Package pkg)
f6faf3
 {
f6faf3
     /* check if the package has a dependency with a '~' */
f6faf3
-    if (haveTildeDep(pkg))
f6faf3
+    if (haveCharInDep(pkg, '~'))
f6faf3
 	(void) rpmlibNeedsFeature(pkg, "TildeInVersions", "4.10.0-1");
f6faf3
 
f6faf3
     /* check if the package has a rich dependency */
f6faf3
-- 
f6faf3
2.23.0
f6faf3