michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 5 months ago
Clone

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

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