From 10a5dcfe3326a24c4a8a88d1f1601d7940bfc53e Mon Sep 17 00:00:00 2001 From: huangwenbin Date: Mon, 31 Aug 2026 15:14:23 +0800 Subject: [PATCH] tools: fix positional input file handling in scmp_bpf_disasm 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 --- tools/scmp_bpf_disasm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c index 45726591..a87ac165 100644 --- a/tools/scmp_bpf_disasm.c +++ b/tools/scmp_bpf_disasm.c @@ -46,7 +46,7 @@ */ static void exit_usage(const char *program) { - fprintf(stderr, "usage: %s -a [-d] [-h]\n", program); + fprintf(stderr, "usage: %s -a [-d] [-h] [bpf_file]\n", program); exit(EINVAL); } @@ -522,8 +522,8 @@ int main(int argc, char *argv[]) } } - if ((optind > 1) && (optind < argc)) { - int opt_file = optind - 1 ; + if (optind < argc) { + int opt_file = optind; file = fopen(argv[opt_file], "r"); if (file == NULL) { fprintf(stderr, "error: unable to open \"%s\" (%s)\n",