aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-10-07 13:44:31 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-10-07 14:17:02 +0700
commitef4c597b4aea28611e1c7fa74464a1b189c45f35 (patch)
tree6e8c1baec862a19889104fd0f98844a98a3c051c
parent7e1a78fb03fb32ff7e9ea3da0ae1e944a93fffee (diff)
vty/command: restrict the use of '.', '!', and '@' as flags
-rw-r--r--include/osmocom/vty/vty.h3
-rw-r--r--src/vty/command.c5
-rw-r--r--src/vty/vty.c9
-rw-r--r--tests/vty/vty_test.c7
-rw-r--r--tests/vty/vty_test.err3
5 files changed, 27 insertions, 0 deletions
diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h
index 9cadb7ac..4e83b1bb 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 d64902ba..d71f686f 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -4309,6 +4309,11 @@ static __attribute__((constructor)) void on_dso_load(void)
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 d12efa00..f4e8e80f 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -1810,6 +1810,15 @@ void vty_init(struct vty_app_info *app_info)
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 3a69e13b..1db0d5ce 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -521,6 +521,9 @@ enum vty_test_attr {
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 @@ int main(int argc, char **argv)
[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 a85b129e..1cb4190c 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