Skip to content

Commit 02c08c9

Browse files
committed
checksec: Do NOT error when passing directory arguments
I often use `checksec *` to lazily avoid typing filenames in a directory. If the directory contains any other sub-dirs, the command fails. With this patch, checksec will silently skip dir paths. There's still 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 02c08c9

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The table below shows which release corresponds to each branch, and what date th
7474

7575
## 5.0.0 (`dev`)
7676

77+
- [#2530][2530] Do NOT error when passing directory arguments in `checksec`.
7778
- [#2507][2507] Add `+LINUX` and `+WINDOWS` doctest options and start proper testing on Windows
7879
- [#2522][2522] Support starting a kitty debugging window with the 'kitten' command
7980
- [#2524][2524] Raise EOFError during `process.recv` when stdout closes on Windows

pwnlib/commandline/checksec.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@
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 []
3230

3331
if not files:
3432
parser.print_usage()
3533
return
3634

3735
for f in files:
3836
try:
39-
e = ELF(f.name)
37+
e = ELF(f)
4038
except Exception as e:
41-
print("{name}: {error}".format(name=f.name, error=e))
39+
print("{name}: {error}".format(name=f, error=e))
4240

4341
if __name__ == '__main__':
4442
common.main(__file__, main)

0 commit comments

Comments
 (0)