Skip to content

Commit

Permalink
Treat unexpected errors as corrupt packages
Browse files Browse the repository at this point in the history
A corrupt package is the most likely cause of an unexpected error, so
treat it as such.
  • Loading branch information
DemiMarie committed Apr 11, 2021
1 parent ac20a40 commit 41ac6c0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions dnf/rpm/miscutils.py
Expand Up @@ -25,20 +25,20 @@
from dnf.i18n import ucd
from shutil import which

sig_re = re.compile(b'\AV[34] (?:RSA|DSA|EdDSA|ECDSA)/SHA(256|384|512) Signature, key ID [0-9a-f]{8}\Z')
payload_digest_re = re.compile(b'\APayload SHA(256|384|512) digest\Z')
sig_re = re.compile(rb'\AV[34] (?:RSA|DSA|EdDSA|ECDSA)/SHA(256|384|512) Signature, key ID [0-9a-f]{8}\Z')
payload_digest_re = re.compile(rb'\APayload SHA(256|384|512) digest\Z')

def _process_rpm_output(data):
if not data.startswith(b'-:\n') or not data.endswith(b'\n'):
_rpmkeys_parse_error()
return 2
data = data.split(b'\n')[1:-1]
if not data:
return 2
seen_sig, missing_key, not_trusted, not_signed = False, False, False, False
valid = 0
for i in data:
if not i.startswith(b' '):
_rpmkeys_parse_error()
return 2
i = i[4:]
if b': BAD' in i:
return 2
Expand All @@ -56,7 +56,7 @@ def _process_rpm_output(data):
elif payload_digest_re.match(i[:-4]):
valid |= 2
else:
_rpmkeys_parse_error()
return 2
if not_trusted:
return 3
elif missing_key:
Expand Down Expand Up @@ -87,9 +87,9 @@ def _verifyPackageUsingRpmkeys(package, installroot):
stdin=package) as p:
data, _ = p.communicate()
if p.returncode >= 2 or p.returncode < 0:
_rpmkeys_parse_error()
return 2
ret = _process_rpm_output(data)
if type(ret) is int and ret > 0:
if ret > 0:
return ret
return 2 if p.returncode else 0

Expand Down

0 comments on commit 41ac6c0

Please sign in to comment.