Skip to content

Commit 4d9455e

Browse files
committed
checksec: more forgiving when passed directory arguments
I often use `checksec *` to lazily avoid typing filename in a directory. If the directory contains any other sub-dirs, the command fails. With this patch, checksec will silently skip dir paths. There is TOCTOU issue but I don't think checksec do anything important enough to explicitly use try/catch to account for that.
1 parent cff58e1 commit 4d9455e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pwnlib/commandline/checksec.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
parser.add_argument(
1616
'elf',
1717
nargs='*',
18-
type=argparse.FileType('rb'),
1918
help='Files to check'
2019
)
2120
parser.add_argument(
2221
'--file',
2322
nargs='*',
2423
dest='elf2',
2524
metavar='elf',
26-
type=argparse.FileType('rb'),
2725
help='File to check (for compatibility with checksec.sh)'
2826
)
2927

3028
def main(args):
31-
files = args.elf or args.elf2 or []
29+
files = args.elf or args.elf2 or []
30+
files = [open(f, 'rb') for f in filter(os.path.isfile, files)]
3231

3332
if not files:
3433
parser.print_usage()

0 commit comments

Comments
 (0)