Skip to content

Commit ad7b5b8

Browse files
committed
insert-beginning: add some sanity checking on the passed filename
The file should exist, and should not have any '.' or '..' path components. Signed-off-by: Elijah Newren <[email protected]>
1 parent 9ae4ae6 commit ad7b5b8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

contrib/filter-repo-demos/insert-beginning

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ parser.add_argument('--file', type=os.fsencode,
3333
args = parser.parse_args()
3434
if not args.file:
3535
raise SystemExit("Error: Need to specify the --file option")
36+
if any([x == b"." or x== b".." for x in args.file.split(b"/")]):
37+
raise SystemExit(f"Error: Invalid path components in {fr.decode(args.file)}")
38+
if not os.path.isfile(args.file):
39+
raise SystemExit(f"Error: {fr.decode(args.file)} not found")
3640

3741
fhash = subprocess.check_output(['git', 'hash-object', '-w', args.file]).strip()
3842
fmode = b'100755' if os.access(args.file, os.X_OK) else b'100644'

0 commit comments

Comments
 (0)