diff options
author | Phil Sutter <phil@nwl.cc> | 2023-01-25 01:51:43 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-01-31 16:29:26 +0100 |
commit | d6eb6a9fd3878ce4fa01f8d4127f1735988bd07b (patch) | |
tree | 7e61e5935cbc00827b34069ce61ef21c93eeb653 /iptables/xshared.c | |
parent | ca8fb6c21b298b3d96db2bfbf9c74d393bdd4728 (diff) |
Proper fix for "unknown argument" error message
While commit 1b8210f848631 kind of fixed the corner-case of invalid
short-options packed with others, it broke error reporting for
long-options. Revert it and deploy a proper solution:
When passing an invalid short-option, e.g. 'iptables -vaL', getopt_long
sets the variable 'optopt' to the invalid character's value. Use it for
reporting instead of optind if set.
To distinguish between invalid options and missing option arguments,
ebtables-translate optstring needs adjustment.
Fixes: 1b8210f848631 ("ebtables: Fix error message for invalid parameters")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/xshared.c')
-rw-r--r-- | iptables/xshared.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/iptables/xshared.c b/iptables/xshared.c index f93529b1..ac51fac5 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -192,9 +192,12 @@ static int command_default(struct iptables_command_state *cs, if (cs->c == ':') xtables_error(PARAMETER_PROBLEM, "option \"%s\" " "requires an argument", cs->argv[optind-1]); - if (cs->c == '?') - xtables_error(PARAMETER_PROBLEM, "unknown option " - "\"%s\"", cs->argv[optind-1]); + if (cs->c == '?') { + char optoptstr[3] = {'-', optopt, '\0'}; + + xtables_error(PARAMETER_PROBLEM, "unknown option \"%s\"", + optopt ? optoptstr : cs->argv[optind - 1]); + } xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", optarg); } |