Blame SOURCES/early_ds_validation_1247654.patch

fd2bce
From 283cf8b21eba35a82a36989b16d52ec396bc8080 Mon Sep 17 00:00:00 2001
fd2bce
From: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
Date: Tue, 4 Aug 2015 10:55:30 +0200
fd2bce
Subject: [PATCH 5/7] Try to load the OSCAP session early for DS content
fd2bce
 (#1247654)
fd2bce
fd2bce
This gives us an easy way to handle invalid content early enough to prevent any
fd2bce
complicated recovery.
fd2bce
fd2bce
Also, discard the session and create a new one when getting profiles for
fd2bce
particular DS ID - XCCDF ID combination because otherwise we would get wrong
fd2bce
results.
fd2bce
fd2bce
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
---
fd2bce
 org_fedora_oscap/content_handling.py | 11 +++++++++++
fd2bce
 1 file changed, 11 insertions(+)
fd2bce
fd2bce
diff --git a/org_fedora_oscap/content_handling.py b/org_fedora_oscap/content_handling.py
fd2bce
index 8621428..c88b8f1 100644
fd2bce
--- a/org_fedora_oscap/content_handling.py
fd2bce
+++ b/org_fedora_oscap/content_handling.py
fd2bce
@@ -149,11 +149,15 @@ class DataStreamHandler(object):
fd2bce
             msg = "Invalid file path: '%s'" % dsc_file_path
fd2bce
             raise DataStreamHandlingError(msg)
fd2bce
 
fd2bce
+        self._dsc_file_path = dsc_file_path
fd2bce
+
fd2bce
         # create an XCCDF session for the file
fd2bce
         self._session = OSCAP.xccdf_session_new(dsc_file_path)
fd2bce
         if not self._session:
fd2bce
             msg = "'%s' is not a valid SCAP content file" % dsc_file_path
fd2bce
             raise DataStreamHandlingError(msg)
fd2bce
+        if OSCAP.xccdf_session_load(self._session) != 0:
fd2bce
+            raise DataStreamHandlingError(OSCAP.oscap_err_desc())
fd2bce
 
fd2bce
         if tailoring_file_path:
fd2bce
             OSCAP.xccdf_session_set_user_tailoring_file(self._session,
fd2bce
@@ -263,6 +267,13 @@ class DataStreamHandler(object):
fd2bce
         # not found in the cache, needs to be gathered
fd2bce
 
fd2bce
         # set the data stream and component (checklist) for the session
fd2bce
+        OSCAP.xccdf_session_free(self._session)
fd2bce
+
fd2bce
+        self._session = OSCAP.xccdf_session_new(self._dsc_file_path)
fd2bce
+        if not self._session:
fd2bce
+            msg = "'%s' is not a valid SCAP content file" % self._dsc_file_path
fd2bce
+            raise DataStreamHandlingError(msg)
fd2bce
+
fd2bce
         OSCAP.xccdf_session_set_datastream_id(self._session, data_stream_id)
fd2bce
         OSCAP.xccdf_session_set_component_id(self._session, checklist_id)
fd2bce
         if OSCAP.xccdf_session_load(self._session) != 0:
fd2bce
-- 
fd2bce
2.1.0
fd2bce