Skip to content

Commit

Permalink
Percolate errors up from rpmfcHelper()
Browse files Browse the repository at this point in the history
Ignoring the error code from rpmfcHelper() means that invalid dependencies
get silently ignores. Intentionally not stopping at the first error though,
as it's often useful to get all errors at once.

Add testcases for legal and illegal output from dependency generator.

Fixes rpm-software-management#881
  • Loading branch information
pmatilai committed Oct 7, 2019
1 parent ab601b8 commit e220cea
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
19 changes: 13 additions & 6 deletions build/rpmfc.c
Expand Up @@ -958,10 +958,11 @@ static const struct applyDep_s applyDepTable[] = {
{ 0, 0, NULL },
};

static void applyAttr(rpmfc fc, int aix, const char *aname,
static int applyAttr(rpmfc fc, int aix, const char *aname,
const struct exclreg_s *excl,
const struct applyDep_s *dep)
{
int rc = 0;
int n, *ixs;

if (fattrHashGetEntry(fc->fahash, aix, &ixs, &n, NULL)) {
Expand All @@ -970,17 +971,21 @@ static void applyAttr(rpmfc fc, int aix, const char *aname,
mname, "_opts}}", NULL);
if (!rstreq(cmd, "")) {
char *ns = rpmfcAttrMacro(aname, "namespace", NULL);
for (int i = 0; i < n; i++)
rpmfcHelper(fc, ixs[i], excl, dep->type, dep->tag, ns, cmd);
for (int i = 0; i < n; i++) {
if (rpmfcHelper(fc, ixs[i], excl, dep->type, dep->tag, ns, cmd))
rc = 1;
}
free(ns);
}
free(cmd);
free(mname);
}
return rc;
}

static rpmRC rpmfcApplyInternal(rpmfc fc)
{
rpmRC rc = RPMRC_OK;
rpmds ds, * dsp;
int previx;
unsigned int val;
Expand All @@ -1001,8 +1006,10 @@ static rpmRC rpmfcApplyInternal(rpmfc fc)
if (skip & dep->type)
continue;
exclInit(dep->name, &excl);
for (rpmfcAttr *attr = fc->atypes; attr && *attr; attr++, aix++)
applyAttr(fc, aix, (*attr)->name, &excl, dep);
for (rpmfcAttr *attr = fc->atypes; attr && *attr; attr++, aix++) {
if (applyAttr(fc, aix, (*attr)->name, &excl, dep))
rc = RPMRC_FAIL;
}
exclFini(&excl);
}
/* No more additions after this, freeze pool to minimize memory use */
Expand Down Expand Up @@ -1038,7 +1045,7 @@ static rpmRC rpmfcApplyInternal(rpmfc fc)
fc->fddictn->vals[ix]++;

}
return RPMRC_OK;
return rc;
}

static int initAttrs(rpmfc fc)
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Expand Up @@ -70,6 +70,7 @@ EXTRA_DIST += data/SPECS/mini.spec
EXTRA_DIST += data/SPECS/scripts.spec
EXTRA_DIST += data/SPECS/scriptfail.spec
EXTRA_DIST += data/SPECS/selfconflict.spec
EXTRA_DIST += data/SPECS/shebang.spec
EXTRA_DIST += data/SPECS/replacetest.spec
EXTRA_DIST += data/SPECS/triggers.spec
EXTRA_DIST += data/SPECS/filetriggers.spec
Expand Down
23 changes: 23 additions & 0 deletions tests/data/SPECS/shebang.spec
@@ -0,0 +1,23 @@
Name: shebang
Version: 0.1
Release: 1
Summary: Testing shebang dependency generation
Group: Testing
License: GPL
BuildArch: noarch

%description
%{summary}

%install
mkdir -p %{buildroot}/bin
cat << EOF > %{buildroot}/bin/shebang
#!/bin/blabla
echo shebang
EOF

chmod a+x %{buildroot}/bin/shebang

%files
%defattr(-,root,root,-)
/bin/shebang
36 changes: 35 additions & 1 deletion tests/rpmbuild.at
Expand Up @@ -386,7 +386,7 @@ runroot rpmbuild -bb --quiet \
])
AT_CLEANUP

AT_SETUP([Dependency generation])
AT_SETUP([Dependency generation 1])
AT_KEYWORDS([build])
AT_CHECK([

Expand Down Expand Up @@ -427,6 +427,40 @@ Fileprovides:
[])
AT_CLEANUP

AT_SETUP([Dependency generation 2])
AT_KEYWORDS([build])
AT_CHECK([

runroot rpmbuild -bb --quiet \
/data/SPECS/shebang.spec
runroot rpm -qp --requires /build/RPMS/noarch/shebang-0.1-1.noarch.rpm|grep -v ^rpmlib
],
[0],
[/bin/blabla
],
[])
AT_CLEANUP

AT_SETUP([Dependency generation 3])
AT_KEYWORDS([build])
AT_CHECK([

cat << EOF > "${RPMTEST}"/tmp/bad.req
#!/bin/sh
echo 'bad = *'
EOF
chmod a+x "${RPMTEST}"/tmp/bad.req

runroot rpmbuild -bb --quiet \
--define "__script_requires /tmp/bad.req" \
/data/SPECS/shebang.spec
],
[1],
[],
[error: Illegal char '*' (0x2a) in: *
Illegal char '*' (0x2a) in: *
])
AT_CLEANUP

# ------------------------------
# Test spec query functionality
Expand Down

0 comments on commit e220cea

Please sign in to comment.