Handle issues with newlines in elog messages that can trigger an unhandled
authorZac Medico <zmedico@gentoo.org>
Wed, 9 Apr 2008 05:31:53 +0000 (05:31 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 9 Apr 2008 05:31:53 +0000 (05:31 -0000)
ValueError to be raised from a split() call inside collect_ebuild_messages():
* Use \0 to delimit messages, so that that elog messages containing newlines
  are handled correctly.
* Handle a potential ValueError when splitting the message type.
(trunk r9763)

svn path=/main/branches/2.1.2/; revision=9764

bin/isolated-functions.sh
pym/portage.py

index 737c5dfb4b069679ec05e7320540613c76829e08..6bd33cb297b10c15738f8de4016497b3ddfe6269 100644 (file)
@@ -170,7 +170,7 @@ elog_base() {
                        return 1
                        ;;
        esac
-       echo -e "${messagetype} $*" >> "${T}/logging/${EBUILD_PHASE:-other}"
+       echo -ne "${messagetype} $*\n\0" >> "${T}/logging/${EBUILD_PHASE:-other}"
        return 0
 }
 
index ca3445548dc41f739e29b0dbb2ee605430cf35bb..8680c34df4ea042c111607b9e49a4d3538cf36e8 100644 (file)
@@ -535,16 +535,24 @@ def elog_process(cpv, mysettings):
        mylogfiles.reverse()
        all_logentries = {}
        for msgfunction in mylogfiles:
+               filename = os.path.join(path, msgfunction)
                if msgfunction not in portage_const.EBUILD_PHASES:
-                       writemsg("!!! can't process invalid log file: %s\n" % f,
+                       writemsg("!!! can't process invalid log file: '%s'\n" % filename,
                                noiselevel=-1)
                        continue
                if not msgfunction in all_logentries:
                        all_logentries[msgfunction] = []
                lastmsgtype = None
                msgcontent = []
-               for l in open(os.path.join(path, msgfunction), "r").readlines():
-                       msgtype, msg = l.split(" ", 1)
+               for l in open(filename, "r").read().split("\0"):
+                       if not l:
+                               continue
+                       try:
+                               msgtype, msg = l.split(" ", 1)
+                       except ValueError:
+                               writemsg("!!! malformed entry in " + \
+                                       "log file: '%s'\n" % filename, noiselevel=-1)
+                               continue
                        if lastmsgtype is None:
                                lastmsgtype = msgtype
                        if msgtype == lastmsgtype: