diff mbox series

[v6,3/4] log: catch invalid level option number

Message ID 20210406131137.1732110-4-thomas@monjalon.net (mailing list archive)
State Superseded
Delegated to: David Marchand
Headers show
Series log level enhancements | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon April 6, 2021, 1:11 p.m. UTC
The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 becomes a failure in parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

David Marchand April 6, 2021, 2:35 p.m. UTC | #1
On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The parsing check for invalid log level was not trying to catch
> irrelevant numeric values.
> A log level 0 becomes a failure in parsing so it can be caught early.
> A log level higher than the max (8) is accepted with a warning message.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Reviewed-by: David Marchand <david.marchand@redhat.com>
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 38b72fb665..7075a051b8 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@  eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {