RHEL5 – yum update works but pup and yum list-security does not

By: | Comments: 85 Comments

Posted in categories: Antiques, Computer Tips

The RHEL5 machines under my administration experienced an interesting error.  If running pup, whenever there are updates exist, it crashes with the error:

SyntaxError: not well-formed (invalid token)

The error message will be things like

# yum list-security
Loading "rhnplugin" plugin
Loading "security" plugin
Setting up repositories
rhel-i386-server-cluster- 100% |=========================| 1.4 kB    00:00
rhel-i386-server-5        100% |=========================| 1.4 kB    00:00
rhel-i386-server-vt-5     100% |=========================| 1.4 kB    00:00
rhel-i386-server-cluster- 100% |=========================| 1.4 kB    00:00
rhel-i386-server-suppleme 100% |=========================| 1.2 kB    00:00
rhn-tools-rhel-i386-serve 100% |=========================| 1.2 kB    00:00
Reading repository metadata in from local files
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in ?
    yummain.main(sys.argv[1:])
  File "/usr/share/yum-cli/yummain.py", line 102, in main
    result, resultmsgs = do()
  File "/usr/share/yum-cli/cli.py", line 359, in doCommands
    return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd,
self.extcmds)
  File "/usr/lib/yum-plugins/security.py", line 193, in doCommand
    md_info = ysp_gen_metadata(self)
  File "/usr/lib/yum-plugins/security.py", line 58, in ysp_gen_metadata
    md_info.add(repo)
  File "/usr/lib/python2.4/site-packages/yum/update_md.py", line 235, in add
    for event, elem in iterparse(infile):
  File "<string>", line 64, in __iter__
SyntaxError: not well-formed (invalid token): line 767, column 15

RedHat Bug 428819 at
https://bugzilla.redhat.com/show_bug.cgi?id=428819
and Bug 470932 at
https://bugzilla.redhat.com/show_bug.cgi?id=470932
explained it as “unescaped ‘&’, ‘<‘, ‘>’ in updateinfo.xml and failing yum-security plugin”
and released an errata at
http://rhn.redhat.com/errata/RHBA-2008-1005.html

However, this errata does not work on my boxes since they are not Network Satellite.

By understanding the detail of the error, a custom fix can be done in the following way:

[root@mybox ~]cd /usr/lib/python2.4/site-packages/yum
[root@mybox yum]nano +376 update_md.py

and insert the following part:

        buffile = open('/root/pup.buf', 'w')
        for line in infile:
            if "<domain>" in line:
                line = line.replace('<domain>', '[domain]')
            if "<pid>" in line:
                line = line.replace('<pid>', '[pid]')
            if "<dev>" in line:
                line = line.replace('<dev>', '[dev]')
            if "<device>" in line:
                line = line.replace('<device>', '[device]')
            if "<head>" in line:
                line = line.replace('<head>', '[head]')
            if "<Unknown>" in line:
                line = line.replace('<Unknown>', '[Unknown]')
            if "<Shift>" in line:
                line = line.replace('<Shift>', '[Shift]')
            if "<Tab>" in line:
                line = line.replace('<Tab>', '[Tab]')
            if "<Directory>" in line:
                line = line.replace('<Directory>', '[Directory]')
            if "<locale>" in line:
                line = line.replace('<locale>', '[locale]')
            if "<source>" in line:
                line = line.replace('<source>', '[source]')
            if "<dest>" in line:
                line = line.replace('<dest>', '[dest]')
            if "<file>" in line:
                line = line.replace('<file>', '[file]')
            if "<NUM>" in line:
                line = line.replace('<NUM>', '[NUM]')
            if "<path_to_file>" in line:
                line = line.replace('<path_to_file>', '[path_to_file]')
            if "<TD>" in line:
                line = line.replace('<TD>', '[TD]')
            if "<Target" in line:
                line = line.replace('<Target', '[Target')
            if "Tag>" in line:
                line = line.replace('Tag>', 'Tag]')
            if "&" in line:
                line = line.replace('&', 'a')
            if "<<" in line:
                line = line.replace('<<', '[[')
            if ">>" in line:
                line = line.replace('>>', ']]')
            if " < " in line:
                line = line.replace(' < ', ' lt ')
            if " > " in line:
                line = line.replace(' > ', ' gt ')
            buffile.write(line)
        buffile.close()
        infile = open('/root/pup.buf', 'rt')

in between

            infile = obj

and

        for event, elem in iterparse(infile):

This will restore the proper operation of pup and yum list-security.

PS. The list has grown too long. The working update_md.py files is here.

If it does not work, you can check the error and put in more replacement filters.

Enjoy.

85 Comments

Leave a Reply