test/cmd_ut.c: fix cmd_ut_category
authorPhilippe Reynes <philippe.reynes@softathome.com>
Thu, 9 Jan 2020 16:34:02 +0000 (17:34 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 10 Jan 2020 19:18:26 +0000 (14:18 -0500)
In the function cmd_ut_category, the prefix is used with
the function strncmp to know if the prefix should be
removed from the test name, even if the prefix is NULL.

To avoid this issue, we consider that a prefix NULL
mean no prefix. So we only try to remove the prefix
from the test_name if the prefix is not NULL, then
we avoid to call the function strncmp with a NULL
prefix.

Reported-by: Coverity CID 281110
Fixes: 4ad4edfe ("cmd_ut: add a parameter prefix to the function cmd_ut_category")
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
test/cmd_ut.c

index 400719e..a3a9d49 100644 (file)
@@ -26,7 +26,7 @@ int cmd_ut_category(const char *name, const char *prefix,
                const char *test_name = test->name;
 
                /* Remove the prefix */
-               if (!strncmp(test_name, prefix, prefix_len))
+               if (prefix && !strncmp(test_name, prefix, prefix_len))
                        test_name += prefix_len;
 
                if (argc > 1 && strcmp(argv[1], test_name))