Skip to content

Commit c6ff87a

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 <juha.ylinen@nordicsemi.no>
1 parent 0484721 commit c6ff87a

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
@@ -252,7 +252,8 @@ def _printf_parameters(self, typ: str, var: str) -> Tuple[str, List[str]]:
252252
DEFAULT_H_OUTPUT_FILE_NAME = 'tests/include/test/psa_test_wrappers.h'
253253

254254
def main() -> None:
255-
parser = argparse.ArgumentParser(description=globals()['__doc__'])
255+
parser = argparse.ArgumentParser(description=globals()['__doc__'],
256+
allow_abbrev=False)
256257
parser.add_argument('--log',
257258
help='Stream to log to (default: no logging code)')
258259
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
@@ -52,7 +52,7 @@
5252
]
5353

5454
def main():
55-
parser = argparse.ArgumentParser()
55+
parser = argparse.ArgumentParser(allow_abbrev=False)
5656
default_output_path = os.path.join(TEST_DIR, 'src', 'test_certs.h')
5757
parser.add_argument('--output', type=str, default=default_output_path)
5858
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)