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

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