From 6df2e44404bd710b13539a09450117f755498c65 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 11 Jun 2019 21:19:46 +0200 Subject: vty: command.c: Fix is_cmd_ambiguous() returning always 0 inner block defined variable "enum match_type ret" was being masking outter block variable "int ret = 0". The ret variable was being given non zero values only inside the inner block, so that change was done on the inner variable and not the outer one, which is returned. Fixes: 5314c513f23688462d7f7937e5ae5e0d5cd4548e Change-Id: Iec87d7db49a096d07e38ff8a060b923a52bfd6ba --- src/vty/command.c | 10 ++++---- tests/tdef/tdef_vty_test_config_root.vty | 41 +++++--------------------------- tests/vty/vty_transcript_test.vty | 6 ++--- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/vty/command.c b/src/vty/command.c index 6380487e..e9690bbf 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -1521,7 +1521,7 @@ is_cmd_ambiguous(char *command, vector v, int index, enum match_type type) if (!desc) continue; - enum match_type ret; + enum match_type mtype; const char *str = desc->cmd; if (CMD_OPTION(str)) { @@ -1573,10 +1573,10 @@ is_cmd_ambiguous(char *command, vector v, int index, enum match_type type) match++; break; case ipv6_prefix_match: - if ((ret = + if ((mtype = cmd_ipv6_prefix_match (command)) != no_match) { - if (ret == partly_match) { + if (mtype == partly_match) { ret = 2; /* There is incomplete match. */ goto free_and_return; } @@ -1590,10 +1590,10 @@ is_cmd_ambiguous(char *command, vector v, int index, enum match_type type) match++; break; case ipv4_prefix_match: - if ((ret = + if ((mtype = cmd_ipv4_prefix_match (command)) != no_match) { - if (ret == partly_match) { + if (mtype == partly_match) { ret = 2; /* There is incomplete match. */ goto free_and_return; } diff --git a/tests/tdef/tdef_vty_test_config_root.vty b/tests/tdef/tdef_vty_test_config_root.vty index e7c96ca3..8613ff36 100644 --- a/tests/tdef/tdef_vty_test_config_root.vty +++ b/tests/tdef/tdef_vty_test_config_root.vty @@ -115,32 +115,13 @@ tdef_vty_test(config)# do show timer tea T-123 % Invalid T timer argument (should be 'T1234' or 'X1234'): 'T-123' tdef_vty_test(config)# do show timer t -tea: T1 = 50 s Water Boiling Timeout (default: 50 s) -tea: T2 = 300 s Tea brewing (default: 300 s) -tea: T3 = 5 m Let tea cool down before drinking (default: 5 m) -tea: T4 = 20 m Forgot to drink tea while it's warm (default: 20 m) -test: T1 = 100 s Testing a hundred seconds (default: 100 s) -test: T2 = 100 ms Testing a hundred milliseconds (default: 100 ms) -test: T3 = 100 m Testing a hundred minutes (default: 100 m) -test: T4 = 100 Testing a hundred potatoes (default: 100) -test: T2147483647 = 4294967295 m Very large (default: 4294967295 m) -test: X23 = 239471 s Negative T number (default: 239471 s) +% Ambiguous command. tdef_vty_test(config)# do show timer te -tea: T1 = 50 s Water Boiling Timeout (default: 50 s) -tea: T2 = 300 s Tea brewing (default: 300 s) -tea: T3 = 5 m Let tea cool down before drinking (default: 5 m) -tea: T4 = 20 m Forgot to drink tea while it's warm (default: 20 m) -test: T1 = 100 s Testing a hundred seconds (default: 100 s) -test: T2 = 100 ms Testing a hundred milliseconds (default: 100 ms) -test: T3 = 100 m Testing a hundred minutes (default: 100 m) -test: T4 = 100 Testing a hundred potatoes (default: 100) -test: T2147483647 = 4294967295 m Very large (default: 4294967295 m) -test: X23 = 239471 s Negative T number (default: 239471 s) +% Ambiguous command. tdef_vty_test(config)# do show timer te T2 -tea: T2 = 300 s Tea brewing (default: 300 s) -test: T2 = 100 ms Testing a hundred milliseconds (default: 100 ms) +% Ambiguous command. tdef_vty_test(config)# timer tea 3 30 @@ -174,20 +155,10 @@ tea: T3 = 32 m Let tea cool down before drinking (default: 5 m) tea: T4 = 20 m Forgot to drink tea while it's warm (default: 20 m) tdef_vty_test(config)# timer t -tea: T1 = 50 s Water Boiling Timeout (default: 50 s) -tea: T2 = 300 s Tea brewing (default: 300 s) -tea: T3 = 32 m Let tea cool down before drinking (default: 5 m) -tea: T4 = 20 m Forgot to drink tea while it's warm (default: 20 m) -test: T1 = 100 s Testing a hundred seconds (default: 100 s) -test: T2 = 100 ms Testing a hundred milliseconds (default: 100 ms) -test: T3 = 100 m Testing a hundred minutes (default: 100 m) -test: T4 = 100 Testing a hundred potatoes (default: 100) -test: T2147483647 = 4294967295 m Very large (default: 4294967295 m) -test: X23 = 239471 s Negative T number (default: 239471 s) +% Ambiguous command. tdef_vty_test(config)# timer te T2 -tea: T2 = 300 s Tea brewing (default: 300 s) -test: T2 = 100 ms Testing a hundred milliseconds (default: 100 ms) +% Ambiguous command. tdef_vty_test(config)# timer test T2 100 @@ -195,7 +166,7 @@ tdef_vty_test(config)# timer tes T2 100 % Error: no timers found tdef_vty_test(config)# timer te T2 100 -% Error: no timers found +% Ambiguous command. tdef_vty_test(config)# do show timer software diff --git a/tests/vty/vty_transcript_test.vty b/tests/vty/vty_transcript_test.vty index 27dacdca..5ed3c1d7 100644 --- a/tests/vty/vty_transcript_test.vty +++ b/tests/vty/vty_transcript_test.vty @@ -19,7 +19,7 @@ vty_transcript_test> multi0 o ok argc=1 o vty_transcript_test> multi0 t -ok argc=1 t +% Ambiguous command. vty_transcript_test> multi0 th ok argc=1 th @@ -42,7 +42,7 @@ vty_transcript_test> multi1 o ok argc=1 o vty_transcript_test> multi1 t -ok argc=1 t +% Ambiguous command. vty_transcript_test> multi1 th ok argc=1 th @@ -74,4 +74,4 @@ vty_transcript_test> multi1 on ok argc=1 on vty_transcript_test> multi2 t -ok argc=1 t +% Ambiguous command. -- cgit v1.2.3