From 31c6c1dd81e666db85538e41459b839c8907a595 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Wed, 21 Nov 2018 15:36:35 +0100 Subject: [PATCH] build: check rich dependencies for special characters Reported-by: Michael Schroeder (cherry picked from commit e7fa1f1c1c4a6161c2254c761e857fdf04fba5ef) --- build/pack.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/build/pack.c b/build/pack.c index 1348b5f675..6925d379fe 100644 --- a/build/pack.c +++ b/build/pack.c @@ -281,12 +281,36 @@ static rpmRC processScriptFiles(rpmSpec spec, Package pkg) return rc; } -static int haveTildeDep(Package pkg) +struct charInDepData { + char c; + int present; +}; + +static rpmRC charInDepCb(void *cbdata, rpmrichParseType type, + const char *n, int nl, const char *e, int el, rpmsenseFlags sense, + rpmrichOp op, char **emsg) { + struct charInDepData *data = cbdata; + if (memchr(e, data->c, el)) + data->present = 1; + + return RPMRC_OK; +} + +static int haveCharInDep(Package pkg, char c) { + struct charInDepData data = {c, 0}; for (int i = 0; i < PACKAGE_NUM_DEPS; i++) { rpmds ds = rpmdsInit(pkg->dependencies[i]); while (rpmdsNext(ds) >= 0) { - if (strchr(rpmdsEVR(ds), '~')) + if (rpmdsIsRich(ds)) { + const char *depstr = rpmdsN(ds); + rpmrichParse(&depstr, NULL, charInDepCb, &data); + } else { + const char *evr = rpmdsEVR(ds); + if (strchr(evr, c)) + data.present = 1; + } + if (data.present) return 1; } } @@ -375,7 +399,7 @@ static char *getIOFlags(Package pkg) static void finalizeDeps(Package pkg) { /* check if the package has a dependency with a '~' */ - if (haveTildeDep(pkg)) + if (haveCharInDep(pkg, '~')) (void) rpmlibNeedsFeature(pkg, "TildeInVersions", "4.10.0-1"); /* check if the package has a rich dependency */