From: Xin Shi Date: Fri, 28 Jul 2023 01:38:24 +0000 (+0800) Subject: dbus-daemon: Avoid known options being interpreted as optional arguments X-Git-Tag: dbus-1.15.8~32^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86a89967f2ff8daf210d8abd0da2542e325b1ba3;p=thirdparty%2Fdbus.git dbus-daemon: Avoid known options being interpreted as optional arguments The man page and --help imply that dbus-daemon --print-address --print-pid is a valid/useful thing to do, but because --print-address takes an optional argument, it is ambiguous whether --print-pid is meant to be the argument for --print-address (same as --print-address=--print-pid) or a new option (same as --print-address=1 --print-pid). In fact, before this commit, the dbus-daemon would interpret --print-pid as the optional argument to --print-address, and then fail to parse it because it isn't an integer. Because none of our options are syntactically valid as arguments for any option that takes an optional argument, we can avoid the ambiguity by delaying parsing of optional arguments until all known options have been tried. Resolves: dbus/dbus#467 Signed-off-by: Xin Shi --- diff --git a/bus/main.c b/bus/main.c index c1ae5e726..cf1abc64c 100644 --- a/bus/main.c +++ b/bus/main.c @@ -584,16 +584,6 @@ main (int argc, char **argv) if (!_dbus_string_append (&addr_fd, desc)) exit (1); - print_address = TRUE; - } - else if (prev_arg && - strcmp (prev_arg, "--print-address") == 0) - { - check_two_addr_descriptors (&addr_fd, "print-address"); - - if (!_dbus_string_append (&addr_fd, arg)) - exit (1); - print_address = TRUE; } else if (strcmp (arg, "--print-address") == 0) @@ -612,16 +602,6 @@ main (int argc, char **argv) if (!_dbus_string_append (&pid_fd, desc)) exit (1); - print_pid = TRUE; - } - else if (prev_arg && - strcmp (prev_arg, "--print-pid") == 0) - { - check_two_pid_descriptors (&pid_fd, "print-pid"); - - if (!_dbus_string_append (&pid_fd, arg)) - exit (1); - print_pid = TRUE; } else if (strcmp (arg, "--print-pid") == 0) @@ -642,6 +622,26 @@ main (int argc, char **argv) } } #endif + else if (prev_arg && + strcmp (prev_arg, "--print-address") == 0) + { + check_two_addr_descriptors (&addr_fd, "print-address"); + + if (!_dbus_string_append (&addr_fd, arg)) + exit (1); + + print_address = TRUE; + } + else if (prev_arg && + strcmp (prev_arg, "--print-pid") == 0) + { + check_two_pid_descriptors (&pid_fd, "print-pid"); + + if (!_dbus_string_append (&pid_fd, arg)) + exit (1); + + print_pid = TRUE; + } else { usage ();