Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/shell: Disable argument count check if optarg are detected
@ 2018-05-29  8:31 Luiz Augusto von Dentz
  2018-05-29 11:40 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-05-29  8:31 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Command which start with optional arguments might be using optargs
format in which case checking argument count check does not work so
this disables it which shall make things btmgmt work:

[mgmt]# add-adv --help
Usage: add-adv [options] <instance_id>
Options:
	 -u, --uuid <uuid>         Service UUID
	 -d, --adv-data <data>     Advertising Data bytes
	 -s, --scan-rsp <data>     Scan Response Data bytes
	 -t, --timeout <timeout>   Timeout in seconds
	 -D, --duration <duration> Duration in seconds
	 -c, --connectable         "connectable" flag
	 -g, --general-discov      "general-discoverable" flag
	 -l, --limited-discov      "limited-discoverable" flag
	 -n, --scan-rsp-local-name "local-name" flag
	 -a, --scan-rsp-appearance "appearance" flag
	 -m, --managed-flags       "managed-flags" flag
	 -p, --tx-power            "tx-power" flag
e.g.:
	add-adv -u 180d -u 180f -d 080954657374204C45 1
[mgmt]# add-adv -u 180d -u 180f -d 080954657374204C45 1
Instance added: 1
---
 src/shared/shell.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index e7f17e021..97d91577e 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -295,6 +295,7 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
 	size_t len;
 	char *man, *opt;
 	int flags = WRDE_NOCMD;
+	bool optargs = false;
 
 	if (!entry->arg || entry->arg[0] == '\0') {
 		if (argc > 1) {
@@ -323,6 +324,7 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
 			goto optional;
 		}
 		man = strndup(opt, man - opt + 1);
+		optargs = true;
 	}
 
 	if (parse_args(man, &w, "<>", flags) < 0) {
@@ -355,7 +357,7 @@ optional:
 	free(opt);
 
 	/* Check if there are too many arguments */
-	if ((unsigned) argc - 1 > w.we_wordc && !w.we_offs) {
+	if (!optargs && ((unsigned int) argc - 1 > w.we_wordc && !w.we_offs)) {
 		print_text(COLOR_HIGHLIGHT, "Too many arguments: %d > %zu",
 					argc - 1, w.we_wordc);
 		goto fail;
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ] shared/shell: Disable argument count check if optarg are detected
  2018-05-29  8:31 [PATCH BlueZ] shared/shell: Disable argument count check if optarg are detected Luiz Augusto von Dentz
@ 2018-05-29 11:40 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-05-29 11:40 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Tue, May 29, 2018 at 11:31 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Command which start with optional arguments might be using optargs
> format in which case checking argument count check does not work so
> this disables it which shall make things btmgmt work:
>
> [mgmt]# add-adv --help
> Usage: add-adv [options] <instance_id>
> Options:
>          -u, --uuid <uuid>         Service UUID
>          -d, --adv-data <data>     Advertising Data bytes
>          -s, --scan-rsp <data>     Scan Response Data bytes
>          -t, --timeout <timeout>   Timeout in seconds
>          -D, --duration <duration> Duration in seconds
>          -c, --connectable         "connectable" flag
>          -g, --general-discov      "general-discoverable" flag
>          -l, --limited-discov      "limited-discoverable" flag
>          -n, --scan-rsp-local-name "local-name" flag
>          -a, --scan-rsp-appearance "appearance" flag
>          -m, --managed-flags       "managed-flags" flag
>          -p, --tx-power            "tx-power" flag
> e.g.:
>         add-adv -u 180d -u 180f -d 080954657374204C45 1
> [mgmt]# add-adv -u 180d -u 180f -d 080954657374204C45 1
> Instance added: 1
> ---
>  src/shared/shell.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index e7f17e021..97d91577e 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -295,6 +295,7 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
>         size_t len;
>         char *man, *opt;
>         int flags = WRDE_NOCMD;
> +       bool optargs = false;
>
>         if (!entry->arg || entry->arg[0] == '\0') {
>                 if (argc > 1) {
> @@ -323,6 +324,7 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
>                         goto optional;
>                 }
>                 man = strndup(opt, man - opt + 1);
> +               optargs = true;
>         }
>
>         if (parse_args(man, &w, "<>", flags) < 0) {
> @@ -355,7 +357,7 @@ optional:
>         free(opt);
>
>         /* Check if there are too many arguments */
> -       if ((unsigned) argc - 1 > w.we_wordc && !w.we_offs) {
> +       if (!optargs && ((unsigned int) argc - 1 > w.we_wordc && !w.we_offs)) {
>                 print_text(COLOR_HIGHLIGHT, "Too many arguments: %d > %zu",
>                                         argc - 1, w.we_wordc);
>                 goto fail;
> --
> 2.17.0

Applied.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-29 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-29  8:31 [PATCH BlueZ] shared/shell: Disable argument count check if optarg are detected Luiz Augusto von Dentz
2018-05-29 11:40 ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox