From 73454ace6ac6fa45fd2be27675a3c2e2907e45ae Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Tue, 18 Apr 2017 16:22:24 +0200 Subject: [PATCH] log: fix log level regexp matching Fix misuse of regular expression functions, which was producing a segfault. After the patch, it works properly: $ ./build/app/test --no-huge --log-level=pmd,3 RTE>>dump_log_types [...] id 30: user7, level is debug id 31: user8, level is debug id 32: pmd.i40e.init, level is critical id 33: pmd.i40e.driver, level is critical Coverity issue: 143472 Fixes: a5279180f510 ("eal: change several log levels matching a regexp") Reported-by: Jianfeng Tan Signed-off-by: Olivier Matz Acked-by: Ferruh Yigit --- lib/librte_eal/common/eal_common_log.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index fcc28a969b..5f38ca5d9a 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -159,10 +159,14 @@ rte_log_set_level_regexp(const char *pattern, uint32_t level) if (level > RTE_LOG_DEBUG) return -1; + if (regcomp(&r, pattern, 0) != 0) + return -1; + for (i = 0; i < rte_logs.dynamic_types_len; i++) { if (rte_logs.dynamic_types[i].name == NULL) continue; - if (regexec(&r, pattern, 0, NULL, 0) == 0) + if (regexec(&r, rte_logs.dynamic_types[i].name, 0, + NULL, 0) == 0) rte_logs.dynamic_types[i].loglevel = level; } -- 2.20.1