diff --git a/lib/rpmte.cc b/lib/rpmte.cc index 7794ffd7ff..a50c7478b0 100644 --- a/lib/rpmte.cc +++ b/lib/rpmte.cc @@ -151,8 +151,15 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs) p->release = headerGetAsString(h, RPMTAG_RELEASE); /* name, version and release are required in all packages */ - if (p->name == NULL || p->version == NULL || p->release == NULL) - goto exit; + for (auto [value, name] : std::vector> + {{p->name, "name"}, + {p->version, "version"}, + {p->release, "release"}}) { + if (value == NULL) { + rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), name.c_str()); + goto exit; + } + } p->epoch = headerGetAsString(h, RPMTAG_EPOCH); @@ -163,6 +170,10 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs) if (p->type == TR_REMOVED && rstreq(p->name, "gpg-pubkey")) { rpmlog(RPMLOG_WARNING, "Erasing gpg-pubkey packages is deprecated! Use rpmkeys.\n"); } else { + if (p->arch == NULL) + rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), "arch"); + if (p->os == NULL) + rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), "os"); goto exit; } } diff --git a/tests/rpmpython.at b/tests/rpmpython.at index 0fb516e3bf..48fe1264f0 100644 --- a/tests/rpmpython.at +++ b/tests/rpmpython.at @@ -340,6 +340,31 @@ for e in ts: [adding upgrade to transaction failed] ) +RPMPY_TEST([add bogus package to transaction 3],[ + +for tag in ["os", "arch", "name", "version", "release"]: + h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm') + del h[tag] + try: + ts.addInstall(h, 'foo', 'u') + except rpm.error as err: + myprint(err) +for e in ts: + myprint(e.NEVRA()) +], +[adding upgrade to transaction failed +adding upgrade to transaction failed +adding upgrade to transaction failed +adding upgrade to transaction failed +adding upgrade to transaction failed +], +[error: Package is missing os +error: Package is missing arch +error: Package is missing name +error: Package is missing version +error: Package is missing release +]) + RPMPY_TEST([transaction element userdata],[ mydata = { 'foo': 'bar', 'capstest': 'lock' } ts.addInstall('${RPMDATA}/RPMS/foo-1.0-1.noarch.rpm', 'u')