collect_ebuild_messages: validate msg type
authorZac Medico <zmedico@gentoo.org>
Fri, 18 Nov 2011 02:55:28 +0000 (18:55 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 18 Nov 2011 02:55:28 +0000 (18:55 -0800)
This will handle invalid message types like the one that triggers the
KeyError in dblink._elog_process for bug #390833. It will also output
the content of the line in order to help diagnose the source of
corruption.

pym/portage/elog/messages.py

index f5232d3e2420ee313fd962a36a50c84e0636630a..98d6206d057f19de95979e4c26de16c8662ef23c 100644 (file)
@@ -18,6 +18,14 @@ from portage import _unicode_decode
 import io
 import sys
 
+_log_levels = frozenset([
+       "ERROR",
+       "INFO",
+       "LOG",
+       "QA",
+       "WARN",
+])
+
 def collect_ebuild_messages(path):
        """ Collect elog messages generated by the bash logging function stored 
                at 'path'.
@@ -52,9 +60,11 @@ def collect_ebuild_messages(path):
                                continue
                        try:
                                msgtype, msg = l.split(" ", 1)
+                               if msgtype not in _log_levels:
+                                       raise ValueError(msgtype)
                        except ValueError:
                                writemsg(_("!!! malformed entry in "
-                                       "log file: '%s'\n") % filename, noiselevel=-1)
+                                       "log file: '%s': %s\n") % (filename, l), noiselevel=-1)
                                continue
 
                        if lastmsgtype is None: