From 1cea3c481ee9753302605ec7648a3402ea27ddac Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 2 Jun 2014 15:27:10 +0100 Subject: [PATCH 76/77] Make sure grub password regex handles all cases The regex to match passwords in grub.conf needs to handle both the --md5 and non-md5 cases and to apply the substitution only to the secret part (password or password hash). This needs to deal with the fact that python will return 'None' for unmatched pattern groups leading to an exception in re.subn() if not all referenced groups match for a given string (in contrast to e.g. the perl approach of treating these groups as the empty string). Make this explicit by using an empty alternate in the possibly unmatched '--md5' group: r"(password\s*)(--md5\s*|\s*)(.*)", r"\1\2********" Signed-off-by: Bryn M. Reeves --- sos/plugins/grub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sos/plugins/grub.py b/sos/plugins/grub.py index 33b9f7a..926439f 100644 --- a/sos/plugins/grub.py +++ b/sos/plugins/grub.py @@ -33,8 +33,8 @@ class Grub(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): def postproc(self): self.do_path_regex_sub( r".*\/grub.conf", - r"(password)\s(--md5)\s(.*)", - r"\1 \2 ********" + r"(password\s*)(--md5\s*|\s*)(.*)", + r"\1\2********" ) # vim: et ts=4 sw=4 -- 1.9.3