From 296f7d30ddfda8603e98be42ac10fa8787ab2728 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 31 Jan 2020 10:36:02 -0500 Subject: [PATCH] Extend overwrite protection to ipmi module This affords the same protection that the redfish module now has. Change-Id: Icc3e4f90427b2912d4d18d60af6f1f599b8005d9 --- pyghmi/ipmi/command.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index d886258d..c6225ee3 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -16,6 +16,7 @@ """This represents the low layer message framing portion of IPMI""" from itertools import chain +import os import socket import struct import threading @@ -454,6 +455,10 @@ class Command(object): return rsp def get_diagnostic_data(self, savefile, progress=None, autosuffix=False): + if os.path.exists(savefile) and not os.path.isdir(savefile): + raise exc.InvalidParameterValue( + 'Not allowed to overwrite existing file: {0}'.format( + savefile)) self.oem_init() return self._oem.get_diagnostic_data(savefile, progress, autosuffix) @@ -2034,6 +2039,10 @@ class Command(object): return self._oem.delete_license(name) def save_licenses(self, directory): + if os.path.exists(directory) and not os.path.isdir(directory): + raise exc.InvalidParameterValue( + 'Not allowed to overwrite existing file: {0}'.format( + directory)) self.oem_init() return self._oem.save_licenses(directory)