eal: use bare option string as name
authorGaetan Rivet <gaetan.rivet@6wind.com>
Thu, 20 Dec 2018 17:06:40 +0000 (18:06 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 15 Jan 2019 01:40:40 +0000 (02:40 +0100)
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
lib/librte_telemetry/rte_telemetry.c

index 088e0fd..3fbc13a 100644 (file)
@@ -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;
                }
index 7fb247e..b2972d7 100644 (file)
@@ -1820,7 +1820,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
 };