[v1,1/8] option: use bare option string as name

Message ID d597dd25a0411e0dae1e6e4c9afa51b8fa06b175.1545325395.git.gaetan.rivet@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Clean up rte_option |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gaëtan Rivet Dec. 20, 2018, 5:06 p.m. UTC
  Current options name can be passed with arbitrary format.
Force the use of "--" prefix and thus POSIX long options format.

This restricts the ability to introduce surprising options and will help
future additional checks.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/rte_option.c   | 6 +++++-
 lib/librte_telemetry/rte_telemetry.c | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/librte_eal/common/rte_option.c b/lib/librte_eal/common/rte_option.c
index 088e0fd23..3fbc13a6a 100644
--- a/lib/librte_eal/common/rte_option.c
+++ b/lib/librte_eal/common/rte_option.c
@@ -20,9 +20,13 @@  static struct rte_option *option;
 int
 rte_option_parse(const char *opt)
 {
+	if (strlen(opt) <= 2 ||
+	    strncmp(opt, "--", 2))
+		return -1;
+
 	/* Check if the option is registered */
 	TAILQ_FOREACH(option, &rte_option_list, next) {
-		if (strcmp(opt, option->opt_str) == 0) {
+		if (strcmp(&opt[2], option->opt_str) == 0) {
 			option->enabled = 1;
 			return 0;
 		}
diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c
index 016431f12..3080bb715 100644
--- a/lib/librte_telemetry/rte_telemetry.c
+++ b/lib/librte_telemetry/rte_telemetry.c
@@ -1798,7 +1798,7 @@  rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry, int fd)
 int telemetry_log_level;
 
 static struct rte_option option = {
-	.opt_str = "--telemetry",
+	.opt_str = "telemetry",
 	.cb = &rte_telemetry_init,
 	.enabled = 0
 };