diff --git a/src/python/cctrusted_vm/cvm.py b/src/python/cctrusted_vm/cvm.py index 4334923..ac26eba 100644 --- a/src/python/cctrusted_vm/cvm.py +++ b/src/python/cctrusted_vm/cvm.py @@ -180,9 +180,16 @@ def get_cc_report(self, nonce: bytearray, data: bytearray, extraArgs) -> CcRepor with open(os.path.join(tempdir, "inblob"), 'wb') as inblob_file: inblob_file.write(input_data) - # Read the output of report - with open(os.path.join(tempdir, "outblob"), 'rb') as outblob_file: - td_report = outblob_file.read() + # Read the output of report and prevent case of resource busy + try: + with open(os.path.join(tempdir, "outblob"), 'rb') as outblob_file: + td_report = outblob_file.read() + except OSError: + LOG.error("Read outblob failed with OSError") + return None + except: + LOG.error("Error in opening outblob file.") + return None # Read provider info with open(os.path.join(tempdir, "provider"), 'r', encoding='utf-8') as provider_file: @@ -192,6 +199,10 @@ def get_cc_report(self, nonce: bytearray, data: bytearray, extraArgs) -> CcRepor with open(os.path.join(tempdir, "generation"), 'r', encoding='utf-8') \ as generation_file: generation = generation_file.read() + # Check if the outblob has been corrupted during file open + if int(generation) > 1: + LOG.error("Found corrupted generation. Skipping attestation report fetching...") + return None if os.path.exists(os.path.join(tempdir, "auxblob")): with open(os.path.join(tempdir, "auxblob"), 'rb') as auxblob_file: