Blob Blame History Raw
From 283cf8b21eba35a82a36989b16d52ec396bc8080 Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Tue, 4 Aug 2015 10:55:30 +0200
Subject: [PATCH 5/7] Try to load the OSCAP session early for DS content
 (#1247654)

This gives us an easy way to handle invalid content early enough to prevent any
complicated recovery.

Also, discard the session and create a new one when getting profiles for
particular DS ID - XCCDF ID combination because otherwise we would get wrong
results.

Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
 org_fedora_oscap/content_handling.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/org_fedora_oscap/content_handling.py b/org_fedora_oscap/content_handling.py
index 8621428..c88b8f1 100644
--- a/org_fedora_oscap/content_handling.py
+++ b/org_fedora_oscap/content_handling.py
@@ -149,11 +149,15 @@ class DataStreamHandler(object):
             msg = "Invalid file path: '%s'" % dsc_file_path
             raise DataStreamHandlingError(msg)
 
+        self._dsc_file_path = dsc_file_path
+
         # create an XCCDF session for the file
         self._session = OSCAP.xccdf_session_new(dsc_file_path)
         if not self._session:
             msg = "'%s' is not a valid SCAP content file" % dsc_file_path
             raise DataStreamHandlingError(msg)
+        if OSCAP.xccdf_session_load(self._session) != 0:
+            raise DataStreamHandlingError(OSCAP.oscap_err_desc())
 
         if tailoring_file_path:
             OSCAP.xccdf_session_set_user_tailoring_file(self._session,
@@ -263,6 +267,13 @@ class DataStreamHandler(object):
         # not found in the cache, needs to be gathered
 
         # set the data stream and component (checklist) for the session
+        OSCAP.xccdf_session_free(self._session)
+
+        self._session = OSCAP.xccdf_session_new(self._dsc_file_path)
+        if not self._session:
+            msg = "'%s' is not a valid SCAP content file" % self._dsc_file_path
+            raise DataStreamHandlingError(msg)
+
         OSCAP.xccdf_session_set_datastream_id(self._session, data_stream_id)
         OSCAP.xccdf_session_set_component_id(self._session, checklist_id)
         if OSCAP.xccdf_session_load(self._session) != 0:
-- 
2.1.0