Blob Blame Raw
From e60ae9f56c5309f0424c9d47eb97b5b5cc1eec97 Mon Sep 17 00:00:00 2001
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
Date: Tue, 28 May 2013 14:45:38 +0200
Subject: [PATCH] Check if spec.get_section returned None before using it

Depending on the check in question it either fails when given section is
missing or possibly even succeeds.

Non-existing %install section is something which should never happen really but
apparently there are people who manage...So let's not crash

See https://bugzilla.redhat.com/show_bug.cgi?id=967571
---
 plugins/generic.py | 9 ++++++++-
 plugins/java.py    | 4 ++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/plugins/generic.py b/plugins/generic.py
index 5f5b867..289b677 100644
--- a/plugins/generic.py
+++ b/plugins/generic.py
@@ -232,6 +232,9 @@ class CheckCleanBuildroot(GenericCheckBase):
         buildroot = buildroot.replace('+', r'\+')
         regex = regex.replace('@buildroot@', buildroot)
         install_sec = self.spec.get_section('%install', raw=True)
+        if not install_sec:
+            self.set_passed(self.NA)
+            return
         self.log.debug('regex: ' + regex)
         self.log.debug('install_sec: ' + install_sec)
         has_clean = install_sec and re.search(regex, install_sec)
@@ -782,7 +785,7 @@ class CheckMakeinstall(GenericCheckBase):
 
     def run_on_applicable(self):
         install = self.spec.get_section('%install', raw=True)
-        if '%makeinstall' in install:
+        if install and '%makeinstall' in install:
             self.set_passed(self.PENDING,
                             '%makeinstall used in %install section')
         else:
@@ -1330,6 +1333,10 @@ class CheckUpdateDesktopDatabase(GenericCheckBase):
         using = []
         failed = False
         install = self.spec.get_section('%install', raw=True)
+        if not install:
+            self.set_passed(self.NA)
+            return
+
         for pkg in self.spec.packages:
             if self.rpms.find('*.desktop', pkg):
                 using.append(pkg)
diff --git a/plugins/java.py b/plugins/java.py
index 142bfb5..92f9566 100644
--- a/plugins/java.py
+++ b/plugins/java.py
@@ -390,8 +390,8 @@ class CheckTestSkip(JavaCheckBase):
         xmvn_skip_regex = re.compile(r'mvn-build\s+.*(-f|--force|'
                                       '--skip-tests).*')
         build_section = self.spec.get_section('%build', raw=True)
-        if (skip_regex.search(build_section) or
-            xmvn_skip_regex.search(build_section)):
+        if build_section and (skip_regex.search(build_section) or
+                              xmvn_skip_regex.search(build_section)):
             self.set_passed(self.PENDING, """Tests seem to be skipped. Verify
         there is a commment giving a reason for this""")
         else:
-- 
1.8.1.4