From 3c19853f6cec7ab00cfd6b098cf8bf7dc54324c4 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 13 Mar 2021 00:22:39 +0100 Subject: [PATCH] ROMFS pruner: Detect spurious tabs This is necessary to make sure that users cannot insert tabs into shell commands. --- Tools/px_romfs_pruner.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tools/px_romfs_pruner.py b/Tools/px_romfs_pruner.py index 31d9de20d3..46b9eff80f 100644 --- a/Tools/px_romfs_pruner.py +++ b/Tools/px_romfs_pruner.py @@ -61,6 +61,8 @@ def main(): help="Board architecture for this run") args = parser.parse_args() + err_count = 0 + # go through temp folder for (root, dirs, files) in os.walk(args.folder): for file in files: @@ -90,8 +92,17 @@ def main(): # read file line by line pruned_content = "" board_excluded = False + with io.open(file_path, "r", newline=None) as f: for line in f: + # abort if spurious tabs are found + if re.search(r"[a-zA-Z0-9]+\t.+", line): + file_local = re.sub(args.folder, '', file_path) + print("ERROR: Spurious TAB character in file " + file_local) + print("Line: " + line) + err_count += 1 + + # find excluded boards if re.search(r'\b{0} exclude\b'.format(args.board), line): board_excluded = True # handle mixer files differently than startup files @@ -116,6 +127,9 @@ def main(): else: os.remove(file_path) + if (err_count > 0): + exit(1) + if __name__ == '__main__': main()