Skip to content

tools: fix positional input file handling in scmp_bpf_disasm - #494

Open
1234binpig wants to merge 1 commit into
seccomp:mainfrom
1234binpig:fix-disasm-positional-file
Open

tools: fix positional input file handling in scmp_bpf_disasm#494
1234binpig wants to merge 1 commit into
seccomp:mainfrom
1234binpig:fix-disasm-positional-file

Conversation

@1234binpig

Copy link
Copy Markdown

Problem

scmp_bpf_disasm uses argv[optind - 1] for the positional input file after option parsing.

Since optind already points to the first remaining positional argument, commands such as:

scmp_bpf_disasm -a x86 filter.bpf

can attempt to open the option argument instead of filter.bpf.

Fix

Use argv[optind] for the positional input file and document the optional [bpf_file] argument in the usage message.

Testing

Verified manually with a generated seccomp-BPF file:

  • positional file input works after the change;
  • -a x86 <file> works correctly;
  • -d -a x86 <file> works correctly.

The full make check suite has an existing regression failure on this environment; the same failure is reproduced on unmodified master.

After getopt() processing, optind points to the first positional
argument. The disassembler instead opened argv[optind - 1], which can
cause an option argument to be treated as the input file.

Use argv[optind] and document the optional BPF input file in the usage
message.

Signed-off-by: huangwenbin <huangwenbin@kylinos.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant