Blame SOURCES/BZ-1234967-handle-invalid-yumdb.patch

5e9bef
commit f5c953e2b8c49187f8e874a53f1bb6ed89e4d810
5e9bef
Author: Michal Domonkos <mdomonko@redhat.com>
5e9bef
Date:   Tue Feb 16 13:42:20 2016 +0100
5e9bef
5e9bef
    Allow for validating attributes read from yumdb
5e9bef
    
5e9bef
    Make sure we don't expose corrupted attributes read from the yumdb to
5e9bef
    the consumers.  There's at least one report of such a corruption: BZ
5e9bef
    1234967.  Instead, make requesting a malformed yumdb attribute
5e9bef
    equivalent to requesting a non-existent one -- which is a valid
5e9bef
    scenario, already handled by the consumers.
5e9bef
    
5e9bef
    Note that the actual validator function that fixes the above bug will be
5e9bef
    committed separately.
5e9bef
5e9bef
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
5e9bef
index 229e1a1..270ade9 100644
5e9bef
--- a/yum/rpmsack.py
5e9bef
+++ b/yum/rpmsack.py
5e9bef
@@ -1755,6 +1755,9 @@ class RPMDBAdditionalDataPackage(object):
5e9bef
                                 'group_member',
5e9bef
                                 'command_line'])
5e9bef
 
5e9bef
+    # Validate these attributes when they are read from a file
5e9bef
+    _validators = {}
5e9bef
+
5e9bef
     def __init__(self, conf, pkgdir, yumdb_cache=None):
5e9bef
         self._conf = conf
5e9bef
         self._mydir = pkgdir
5e9bef
@@ -1903,6 +1906,15 @@ class RPMDBAdditionalDataPackage(object):
5e9bef
         fo.close()
5e9bef
         del fo
5e9bef
 
5e9bef
+        # Validate the attribute we just read from the file.  Some attributes
5e9bef
+        # may require being in a specific format and we can't guarantee the
5e9bef
+        # file has not been tampered with outside of yum.
5e9bef
+        if attr in self._validators:
5e9bef
+            valid = self._validators[attr]
5e9bef
+            if not valid(value):
5e9bef
+                raise AttributeError, \
5e9bef
+                    "Invalid value of attribute %s on %s" % (attr, self)
5e9bef
+
5e9bef
         if info.st_nlink > 1 and self._yumdb_cache is not None:
5e9bef
             self._yumdb_cache[key] = value
5e9bef
         self._auto_cache(attr, value, fn, info)
5e9bef
commit 6972a28059790177ab95e0bce92311aa882ae465
5e9bef
Author: Michal Domonkos <mdomonko@redhat.com>
5e9bef
Date:   Tue Feb 16 13:53:04 2016 +0100
5e9bef
5e9bef
    Don't crash on invalid from_repo in yumdb. BZ 1234967
5e9bef
    
5e9bef
    Implement a yumdb validator function for the from_repo attribute.  This
5e9bef
    prevents yum from crashing if an implicit conversion to unicode takes
5e9bef
    place somewhere and the attribute contains non-ascii chars due to some
5e9bef
    yumdb corruption.
5e9bef
    
5e9bef
    Reproducers:
5e9bef
    
5e9bef
    $ yum install foo
5e9bef
    $ yumdb set from_repo <non-ascii-chars> foo
5e9bef
    $ yum list foo  # crash
5e9bef
    $ yum --disablerepo=<repo-with-foo> reinstall foo  # crash
5e9bef
    $ yum --verbose version installed  # crash
5e9bef
5e9bef
diff --git a/yum/__init__.py b/yum/__init__.py
5e9bef
index 84bea3e..1f6ce16 100644
5e9bef
--- a/yum/__init__.py
5e9bef
+++ b/yum/__init__.py
5e9bef
@@ -95,7 +95,6 @@ from yum.rpmtrans import RPMTransaction,SimpleCliCallBack
5e9bef
 from yum.i18n import to_unicode, to_str, exception2msg
5e9bef
 from yum.drpm import DeltaInfo, DeltaPackage
5e9bef
 
5e9bef
-import string
5e9bef
 import StringIO
5e9bef
 
5e9bef
 from weakref import proxy as weakref
5e9bef
@@ -476,17 +475,7 @@ class YumBase(depsolve.Depsolve):
5e9bef
                 continue
5e9bef
 
5e9bef
             # Check the repo.id against the valid chars
5e9bef
-            bad = None
5e9bef
-            for byte in section:
5e9bef
-                if byte in string.ascii_letters:
5e9bef
-                    continue
5e9bef
-                if byte in string.digits:
5e9bef
-                    continue
5e9bef
-                if byte in "-_.:":
5e9bef
-                    continue
5e9bef
-                
5e9bef
-                bad = byte
5e9bef
-                break
5e9bef
+            bad = misc.validate_repoid(section)
5e9bef
 
5e9bef
             if bad:
5e9bef
                 self.logger.warning("Bad id for repo: %s, byte = %s %d" %
5e9bef
diff --git a/yum/misc.py b/yum/misc.py
5e9bef
index f72f028..345934b 100644
5e9bef
--- a/yum/misc.py
5e9bef
+++ b/yum/misc.py
5e9bef
@@ -24,6 +24,7 @@ import bz2
5e9bef
 import gzip
5e9bef
 import shutil
5e9bef
 import urllib
5e9bef
+import string
5e9bef
 _available_compression = ['gz', 'bz2']
5e9bef
 try:
5e9bef
     import lzma
5e9bef
@@ -1248,3 +1249,12 @@ def filter_pkgs_repoid(pkgs, repoid):
5e9bef
             continue
5e9bef
         ret.append(pkg)
5e9bef
     return ret
5e9bef
+
5e9bef
+def validate_repoid(repoid):
5e9bef
+    """Return the first invalid char found in the repoid, or None."""
5e9bef
+    allowed_chars = string.ascii_letters + string.digits + '-_.:'
5e9bef
+    for char in repoid:
5e9bef
+        if char not in allowed_chars:
5e9bef
+            return char
5e9bef
+    else:
5e9bef
+        return None
5e9bef
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
5e9bef
index 270ade9..11814f1 100644
5e9bef
--- a/yum/rpmsack.py
5e9bef
+++ b/yum/rpmsack.py
5e9bef
@@ -1756,7 +1756,10 @@ class RPMDBAdditionalDataPackage(object):
5e9bef
                                 'command_line'])
5e9bef
 
5e9bef
     # Validate these attributes when they are read from a file
5e9bef
-    _validators = {}
5e9bef
+    _validators = {
5e9bef
+        # Fixes BZ 1234967
5e9bef
+        'from_repo': lambda repoid: misc.validate_repoid(repoid) is None,
5e9bef
+    }
5e9bef
 
5e9bef
     def __init__(self, conf, pkgdir, yumdb_cache=None):
5e9bef
         self._conf = conf
5e9bef
commit c02805ed3b23f97843931e0784d2823b8024e441
5e9bef
Author: Michal Domonkos <mdomonko@redhat.com>
5e9bef
Date:   Tue Feb 16 17:20:26 2016 +0100
5e9bef
5e9bef
    docs: mention special case for unknown from_repo
5e9bef
5e9bef
diff --git a/docs/yum.8 b/docs/yum.8
5e9bef
index e428148..eb52fb7 100644
5e9bef
--- a/docs/yum.8
5e9bef
+++ b/docs/yum.8
5e9bef
@@ -964,6 +964,8 @@ The format of the output of yum list is:
5e9bef
 
5e9bef
 name.arch [epoch:]version-release  repo or @installed-from-repo
5e9bef
 
5e9bef
+Note that if the repo cannot be determined, "installed" is printed instead.
5e9bef
+
5e9bef
 .IP "\fByum list [all | glob_exp1] [glob_exp2] [\&.\&.\&.]\fP"
5e9bef
 List all available and installed packages\&.
5e9bef
 .IP "\fByum list available [glob_exp1] [\&.\&.\&.]\fP"