Skip to content

Commit

Permalink
insert-beginning: add some sanity checking on the passed filename
Browse files Browse the repository at this point in the history
The file should exist, and should not have any '.' or '..' path
components.

Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Nov 24, 2024
1 parent c9dda33 commit 93b3a00
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contrib/filter-repo-demos/insert-beginning
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ parser.add_argument('--file', type=os.fsencode,
args = parser.parse_args()
if not args.file:
raise SystemExit("Error: Need to specify the --file option")
if any([x == b"." or x== b".." for x in args.file.split(b"/")]):
raise SystemExit(f"Error: Invalid path components in {fr.decode(args.file)}")
if not os.path.isfile(args.file):
raise SystemExit(f"Error: {fr.decode(args.file)} not found")

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

0 comments on commit 93b3a00

Please sign in to comment.