mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools/pygrub: Small refactors
Small tidy up to ensure output_directory always has a trailing '/' to ease concatenating paths and that `output` can only be a filename or None. This is part of XSA-443 / CVE-2023-34325 Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
This commit is contained in:
1 parent
f4b504c617
commit
9f2ff9a7c9
1 file changed
+5
-5
@@ -793,7 +793,7 @@ if __name__ == "__main__":
|
||||
debug = False
|
||||
not_really = False
|
||||
output_format = "sxp"
|
||||
output_directory = "/var/run/xen/pygrub"
|
||||
output_directory = "/var/run/xen/pygrub/"
|
||||
|
||||
# what was passed in
|
||||
incfg = { "kernel": None, "ramdisk": None, "args": "" }
|
||||
@@ -815,7 +815,8 @@ if __name__ == "__main__":
|
||||
usage()
|
||||
sys.exit()
|
||||
elif o in ("--output",):
|
||||
output = a
|
||||
if a != "-":
|
||||
output = a
|
||||
elif o in ("--kernel",):
|
||||
incfg["kernel"] = a
|
||||
elif o in ("--ramdisk",):
|
||||
@@ -847,12 +848,11 @@ if __name__ == "__main__":
|
||||
if not os.path.isdir(a):
|
||||
print("%s is not an existing directory" % a)
|
||||
sys.exit(1)
|
||||
output_directory = a
|
||||
output_directory = a + '/'
|
||||
|
||||
if debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
try:
|
||||
os.makedirs(output_directory, 0o700)
|
||||
except OSError as e:
|
||||
@@ -861,7 +861,7 @@ if __name__ == "__main__":
|
||||
else:
|
||||
raise
|
||||
|
||||
if output is None or output == "-":
|
||||
if output is None:
|
||||
fd = sys.stdout.fileno()
|
||||
else:
|
||||
fd = os.open(output, os.O_WRONLY)
|
||||
|
||||