main: misleading error reporting in chain definitions
Pablo Neira Ayuso
maintainerPATCH 1/1 main: misleading error reporting in chain definitions
# nft add chain x y { type filter hook input priority -30\; }
nft: invalid option -- '3'Fix this by restricting getopt_long() to the first curly brace.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/main.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
src/main.c +21 -2
@@ -192,19 +192,38 @@ static const struct { }, }; +static int argc_getopt (int argc,char *const *argv) +{ +int i; + +/* Restrict getopt_long() parsing to the first curly brace, so users +* do not need to invoke nft with an upfront -- to specify chain +* priority. +*/ +for (i =0 ; i < argc; i++) { +if (argv[i][0 ] =='{' ) { +return i; + } + } + +return argc; +} +int main (int argc,char *const *argv) {char *buf =NULL , *filename =NULL ;unsigned int output_flags =0 ; +int i, val, rc, __argc;bool interactive = false;unsigned int debug_mask;unsigned int len; -int i, val, rc; + + __argc =argc_getopt (argc, argv); nft =nft_ctx_new (NFT_CTX_DEFAULT );while (1 ) { - val =getopt_long (argc, argv,OPTSTRING , options,NULL ); + val =getopt_long (__argc, argv,OPTSTRING , options,NULL );if (val ==-1 )break ;
Signature · 1 line
2.11.0
Phil Sutter
reviewerHi Pablo,
Quoted 4 lines · Pablo Neira Ayuso
# nft add chain x y { type filter hook input priority -30\; } nft: invalid option -- '3'Fix this by restricting
getopt_long()to the first curly brace.
Wouldn't it suffice to set the first char of OPTSTRING to '+'? Exporting POSIXLY_CORRECT=1 prior to calling the above command works at least.
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 10 lines · Phil Sutter
Hi Pablo,
Quoted 4 lines · Pablo Neira Ayuso
# nft add chain x y { type filter hook input priority -30\; } nft: invalid option -- '3'Fix this by restricting
getopt_long()to the first curly brace.Wouldn't it suffice to set the first char of OPTSTRING to '+'? Exporting POSIXLY_CORRECT=1 prior to calling the above command works at least.
Would you post a patch? :-)