Change in libosmocore[master]: vty/command: restrict the use of '.', '!', and '@' as flags

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
Wed Oct 7 10:03:47 UTC 2020


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

Change subject: vty/command: restrict the use of '.', '!', and '@' as flags
......................................................................

vty/command: restrict the use of '.', '!', and '@' as flags

Change-Id: Icb4acbab0a15de2b0ed7b88fb0e227675317146a
Related: SYS#4937
---
M include/osmocom/vty/vty.h
M src/vty/command.c
M src/vty/vty.c
M tests/vty/vty_test.c
M tests/vty/vty_test.err
5 files changed, 27 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h
index 9cadb7a..4e83b1b 100644
--- a/include/osmocom/vty/vty.h
+++ b/include/osmocom/vty/vty.h
@@ -30,6 +30,9 @@
 
 /* Number of application / library specific VTY attributes */
 #define VTY_CMD_USR_ATTR_NUM 32
+/* Flag characters reserved for global VTY attributes */
+#define VTY_CMD_ATTR_FLAGS_RESERVED \
+	{ '.', '!', '@' }
 
 /*! VTY events */
 enum event {
diff --git a/src/vty/command.c b/src/vty/command.c
index d64902b..d71f686 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -4309,6 +4309,11 @@
 		if (cmd_lib_attr_letters[i] == '\0')
 			continue;
 
+		/* Some flag characters are reserved for global attributes */
+		const char rafc[] = VTY_CMD_ATTR_FLAGS_RESERVED;
+		for (j = 0; j < ARRAY_SIZE(rafc); j++)
+			OSMO_ASSERT(cmd_lib_attr_letters[i] != rafc[j]);
+
 		/* Only upper case flag letters are allowed for libraries */
 		OSMO_ASSERT(cmd_lib_attr_letters[i] >= 'A');
 		OSMO_ASSERT(cmd_lib_attr_letters[i] <= 'Z');
diff --git a/src/vty/vty.c b/src/vty/vty.c
index d12efa0..f4e8e80 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -1810,6 +1810,15 @@
 		if (app_info->usr_attr_letters[i] == '\0')
 			continue;
 
+		/* Some flag characters are reserved for global attributes */
+		const char rafc[] = VTY_CMD_ATTR_FLAGS_RESERVED;
+		for (j = 0; j < ARRAY_SIZE(rafc); j++) {
+			if (app_info->usr_attr_letters[i] != rafc[j])
+				continue;
+			fprintf(stderr, "Attribute flag character '%c' is reserved "
+				"for globals! Please fix.\n", app_info->usr_attr_letters[i]);
+		}
+
 		/* Upper case flag letters are reserved for libraries */
 		if (app_info->usr_attr_letters[i] >= 'A' &&
 		    app_info->usr_attr_letters[i] <= 'Z') {
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index 3a69e13..1db0d5c 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -521,6 +521,9 @@
 	VTY_TEST_ATTR_FOO_DUP,
 	VTY_TEST_ATTR_ZOO_DUP,
 	VTY_TEST_ATTR_UPPER,
+	VTY_TEST_ATTR_RAFC_DOT,
+	VTY_TEST_ATTR_RAFC_EXCL,
+	VTY_TEST_ATTR_RAFC_AT,
 };
 
 int main(int argc, char **argv)
@@ -538,6 +541,10 @@
 			[VTY_TEST_ATTR_ZOO_DUP]	= 'z',
 			/* Reserved for libraries */
 			[VTY_TEST_ATTR_UPPER]	= 'X',
+			/* Reserved for global attribues */
+			[VTY_TEST_ATTR_RAFC_DOT]	'.',
+			[VTY_TEST_ATTR_RAFC_EXCL]	'!',
+			[VTY_TEST_ATTR_RAFC_AT]		'@',
 		},
 	};
 
diff --git a/tests/vty/vty_test.err b/tests/vty/vty_test.err
index a85b129..1cb4190 100644
--- a/tests/vty/vty_test.err
+++ b/tests/vty/vty_test.err
@@ -1,6 +1,9 @@
 Found duplicate flag letter 'f' in application specific attributes (index 0 vs 3)! Please fix.
 Found duplicate flag letter 'z' in application specific attributes (index 2 vs 4)! Please fix.
 Attribute flag letter 'X' is reserved for libraries! Please fix.
+Attribute flag character '.' is reserved for globals! Please fix.
+Attribute flag character '!' is reserved for globals! Please fix.
+Attribute flag character '@' is reserved for globals! Please fix.
 Got VTY event: 2
 Got VTY event: 2
 Got VTY event: 2

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Icb4acbab0a15de2b0ed7b88fb0e227675317146a
Gerrit-Change-Number: 20472
Gerrit-PatchSet: 2
Gerrit-Owner: Vadim Yanitskiy <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
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/20201007/611e3e0a/attachment.htm>


More information about the gerrit-log mailing list