From 855bf6a85bb70f619112981368ed79f677658acb Mon Sep 17 00:00:00 2001 From: Mitchell Wills Date: Fri, 8 Nov 2019 15:08:59 -0800 Subject: [generate-self-extracting-archive] Cleanup and improve error handling Increase the max extract offset and add some input sanity checks Make the output file executable Test: Ran manually with various license inputs Bug: 125451157 Change-Id: Id76d55479366f1d9b8906e6d04c1a6db8d4d8285 --- tools/generate-self-extracting-archive.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tools/generate-self-extracting-archive.py') diff --git a/tools/generate-self-extracting-archive.py b/tools/generate-self-extracting-archive.py index f0b7568116..5a193ab8ec 100755 --- a/tools/generate-self-extracting-archive.py +++ b/tools/generate-self-extracting-archive.py @@ -91,7 +91,7 @@ def _pipe_bytes(src, dst): break dst.write(b) -_MAX_OFFSET_WIDTH = 8 +_MAX_OFFSET_WIDTH = 20 def _generate_extract_command(start, end, extract_name): """Generate the extract command. @@ -119,6 +119,10 @@ def _generate_extract_command(start, end, extract_name): def main(argv): + if len(argv) != 5: + print 'generate-self-extracting-archive.py expects exactly 4 arguments' + sys.exit(1) + output_filename = argv[1] input_archive_filename = argv[2] comment = argv[3] @@ -129,6 +133,14 @@ def main(argv): with open(license_filename, 'r') as license_file: license = license_file.read() + if not license: + print 'License file was empty' + sys.exit(1) + + if 'SOFTWARE LICENSE AGREEMENT' not in license: + print 'License does not look like a license' + sys.exit(1) + comment_line = '# %s\n' % comment extract_name = os.path.basename(input_archive_filename) @@ -161,5 +173,9 @@ def main(argv): trailing_zip.seek(0) _pipe_bytes(trailing_zip, output) + umask = os.umask(0) + os.umask(umask) + os.chmod(output_filename, 0o777 & ~umask) + if __name__ == "__main__": main(sys.argv) -- cgit v1.2.3-59-g8ed1b