Skip to content

Commit 88b1555

Browse files
committed
Disable allow_abbrev from Python scripts using argparse
Python's argparse library, by default, allows shortening of command line arguments. This can introduce silent failures when shortened commands are used and another command is added to the script which uses that name. Signed-off-by: Juha Ylinen <[email protected]>
1 parent e8b4ae9 commit 88b1555

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

scripts/generate_psa_wrappers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
DEFAULT_H_OUTPUT_FILE_NAME = 'tests/include/test/psa_test_wrappers.h'
1313

1414
def main() -> None:
15-
parser = argparse.ArgumentParser(description=globals()['__doc__'])
15+
parser = argparse.ArgumentParser(description=globals()['__doc__'],
16+
allow_abbrev=False)
1617
parser.add_argument('--log',
1718
help='Stream to log to (default: no logging code)')
1819
parser.add_argument('--output-c',

scripts/generate_test_cert_macros.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
]
5454

5555
def main():
56-
parser = argparse.ArgumentParser()
56+
parser = argparse.ArgumentParser(allow_abbrev=False)
5757
default_output_path = os.path.join(TESTS_DIR, 'src', 'test_certs.h')
5858
parser.add_argument('--output', type=str, default=default_output_path)
5959
parser.add_argument('--list-dependencies', action='store_true')

scripts/generate_test_code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ def main():
12041204
:return:
12051205
"""
12061206
parser = argparse.ArgumentParser(
1207-
description='Dynamically generate test suite code.')
1207+
description='Dynamically generate test suite code.',
1208+
allow_abbrev=False)
12081209

12091210
parser.add_argument("-f", "--functions-file",
12101211
dest="funcs_file",

scripts/generate_test_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def collect_keys() -> Tuple[str, str]:
170170
def main() -> None:
171171
default_output_path = guess_project_root() + "/tests/src/test_keys.h"
172172

173-
argparser = argparse.ArgumentParser()
173+
argparser = argparse.ArgumentParser(allow_abbrev=False)
174174
argparser.add_argument("--output", help="Output file", default=default_output_path)
175175
args = argparser.parse_args()
176176

scripts/mbedtls_framework/test_data_generation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def generate_target(self, name: str, *target_args) -> None:
178178

179179
def main(args, description: str, generator_class: Type[TestGenerator] = TestGenerator):
180180
"""Command line entry point."""
181-
parser = argparse.ArgumentParser(description=description)
181+
parser = argparse.ArgumentParser(description=description,
182+
allow_abbrev=False)
182183
parser.add_argument('--list', action='store_true',
183184
help='List available targets and exit')
184185
parser.add_argument('--list-for-cmake', action='store_true',

0 commit comments

Comments
 (0)