Skip to content

Commit 9c34aea

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 b876a0a commit 9c34aea

23 files changed

+40
-24
lines changed

scripts/abi_check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ def check_for_abi_changes(self):
549549
def run_main():
550550
try:
551551
parser = argparse.ArgumentParser(
552-
description=__doc__
552+
description=__doc__,
553+
allow_abbrev=False
553554
)
554555
parser.add_argument(
555556
"-v", "--verbose", action="store_true",

scripts/assemble_changelog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ def set_defaults(options):
499499

500500
def main():
501501
"""Command line entry point."""
502-
parser = argparse.ArgumentParser(description=__doc__)
502+
parser = argparse.ArgumentParser(description=__doc__,
503+
allow_abbrev=False)
503504
parser.add_argument('--dir', '-d', metavar='DIR',
504505
default='ChangeLog.d',
505506
help='Directory to read entries from'

scripts/code_size_compare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ def get_comparision_results(self) -> None:
857857
self.gen_code_size_comparison()
858858

859859
def main():
860-
parser = argparse.ArgumentParser(description=(__doc__))
860+
parser = argparse.ArgumentParser(description=(__doc__),
861+
allow_abbrev=False)
861862
group_required = parser.add_argument_group(
862863
'required arguments',
863864
'required arguments to parse for running ' + os.path.basename(__file__))

scripts/code_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def main() -> int:
224224
print("Note: The only supported version is " +
225225
UNCRUSTIFY_SUPPORTED_VERSION)
226226

227-
parser = argparse.ArgumentParser()
227+
parser = argparse.ArgumentParser(allow_abbrev=False)
228228
parser.add_argument('-f', '--fix', action='store_true',
229229
help=('modify source files to fix the code style '
230230
'(default: print diff, do not modify files)'))

scripts/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,9 @@ def write(self, filename=None):
485485
def main():
486486
"""Command line mbedtls_config.h manipulation tool."""
487487
parser = argparse.ArgumentParser(description="""
488-
Mbed TLS configuration file manipulation tool.
489-
""")
488+
Mbed TLS configuration file manipulation tool.
489+
""",
490+
allow_abbrev=False)
490491
parser.add_argument('--file', '-f',
491492
help="""File to read (and modify if requested).
492493
Default: {}.

scripts/generate_driver_wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def main() -> int:
167167
"""
168168
def_arg_project_root = build_tree.guess_project_root()
169169

170-
parser = argparse.ArgumentParser()
170+
parser = argparse.ArgumentParser(allow_abbrev=False)
171171
parser.add_argument('--project-root', default=def_arg_project_root,
172172
help='root directory of repo source code')
173173
parser.add_argument('--template-dir',

scripts/generate_ssl_debug_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def main():
400400
"""
401401
Command line entry
402402
"""
403-
parser = argparse.ArgumentParser()
403+
parser = argparse.ArgumentParser(allow_abbrev=False)
404404
parser.add_argument('--mbedtls-root', nargs='?', default=None,
405405
help='root directory of mbedtls source code')
406406
parser.add_argument('output_directory', nargs='?',

scripts/min_requirements.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def install(
9494

9595
def main() -> None:
9696
"""Command line entry point."""
97-
parser = argparse.ArgumentParser(description=__doc__)
97+
parser = argparse.ArgumentParser(description=__doc__,
98+
allow_abbrev=False)
9899
parser.add_argument('--no-act', '-n',
99100
action='store_true',
100101
help="Don't act, just print what will be done")

tests/scripts/analyze_outcomes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ def main():
664664
main_results = Results()
665665

666666
try:
667-
parser = argparse.ArgumentParser(description=__doc__)
667+
parser = argparse.ArgumentParser(description=__doc__,
668+
allow_abbrev=False)
668669
parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
669670
help='Outcome file to analyze')
670671
parser.add_argument('specified_tasks', default='all', nargs='?',

tests/scripts/audit-validity-dates.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ def main():
385385
"""
386386
Perform argument parsing.
387387
"""
388-
parser = argparse.ArgumentParser(description=__doc__)
388+
parser = argparse.ArgumentParser(description=__doc__,
389+
allow_abbrev=False)
389390

390391
parser.add_argument('-a', '--all',
391392
action='store_true',

0 commit comments

Comments
 (0)