Change in libosmocore[master]: vty: Return error if cmd returns CMD_WARNING while reading cfg file

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Oct 28 19:15:29 UTC 2019


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/15827 )

Change subject: vty: Return error if cmd returns CMD_WARNING while reading cfg file
......................................................................

vty: Return error if cmd returns CMD_WARNING while reading cfg file

Otherwise bad configurations can easily sneak in and produce unexpected
behavior.

Change-Id: Ic9c1b566ec4a459f03e6319cf369691903cf9d00
---
M src/vty/command.c
M tests/Makefile.am
A tests/vty/fail_cmd_ret_warning.cfg
M tests/vty/vty_test.c
M tests/vty/vty_test.ok
5 files changed, 29 insertions(+), 2 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/vty/command.c b/src/vty/command.c
index a36f30a..6a9d18a 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -2631,8 +2631,7 @@
 		ret = cmd_execute_command_strict(vline, vty, NULL);
 		cmd_free_strvec(vline);
 
-		if (ret != CMD_SUCCESS && ret != CMD_WARNING
-		    && ret != CMD_ERR_NOTHING_TODO) {
+		if (ret != CMD_SUCCESS && ret != CMD_ERR_NOTHING_TODO) {
 			if (indent) {
 				talloc_free(indent);
 				indent = NULL;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e0993b1..60213ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -293,6 +293,7 @@
 	     vty/fail_not_de-indented.cfg \
 	     vty/fail_tabs_and_spaces.cfg \
 	     vty/fail_too_much_indent.cfg \
+	     vty/fail_cmd_ret_warning.cfg \
 	     vty/ok.cfg \
 	     vty/ok_empty_parent.cfg \
 	     vty/ok_ignore_blank.cfg \
diff --git a/tests/vty/fail_cmd_ret_warning.cfg b/tests/vty/fail_cmd_ret_warning.cfg
new file mode 100644
index 0000000..b03f02a
--- /dev/null
+++ b/tests/vty/fail_cmd_ret_warning.cfg
@@ -0,0 +1,3 @@
+return-success
+return-warning
+return-success
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index 30efb9a..0d68a6c 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -421,8 +421,27 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_ret_success, cfg_ret_success_cmd,
+	"return-success",
+	"testing return success\n")
+{
+	printf("Called: 'return-success'\n");
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ret_warning, cfg_ret_warning_cmd,
+	"return-warning",
+	"testing return warning\n")
+{
+	printf("Called: 'return-warning'\n");
+	return CMD_WARNING;
+}
+
 void test_vty_add_cmds()
 {
+	install_element(CONFIG_NODE, &cfg_ret_warning_cmd);
+	install_element(CONFIG_NODE, &cfg_ret_success_cmd);
+
 	install_element(CONFIG_NODE, &cfg_level1_cmd);
 	install_node(&level1_node, NULL);
 	install_element(LEVEL1_NODE, &cfg_level1_child_cmd);
@@ -524,6 +543,7 @@
 	test_exit_by_indent("fail_tabs_and_spaces.cfg", -EINVAL);
 	test_exit_by_indent("ok_indented_root.cfg", 0);
 	test_exit_by_indent("ok_empty_parent.cfg", 0);
+	test_exit_by_indent("fail_cmd_ret_warning.cfg", -EINVAL);
 
 	test_is_cmd_ambiguous();
 
diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok
index 2f76ff9..0b5ac9c 100644
--- a/tests/vty/vty_test.ok
+++ b/tests/vty/vty_test.ok
@@ -286,6 +286,10 @@
 called level3 node k
 called level1 child cmd k
 got rc=0
+reading file fail_cmd_ret_warning.cfg, expecting rc=-22
+Called: 'return-success'
+Called: 'return-warning'
+got rc=-22
 Going to test is_cmd_ambiguous()
 Going to execute 'ambiguous_nr'
 Called: 'ambiguous_nr [<0-23>]' (argc=0)

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15827
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic9c1b566ec4a459f03e6319cf369691903cf9d00
Gerrit-Change-Number: 15827
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191028/78c44f52/attachment.htm>


More information about the gerrit-log mailing list