diff options
author | Dylan Chung <dylan@andestech.com> | 2019-11-18 17:58:58 +0800 |
---|---|---|
committer | Cyril Hrubis <chrubis@suse.cz> | 2019-11-18 12:51:15 +0100 |
commit | e566f9ac7816b38bf16ba3570806427385dbf98b (patch) | |
tree | 452d4f5f099eb0b86cd956b1be6b26883bd9ff3f | |
parent | 530651d26fb91129e92383cfb23136e0f6c9c23d (diff) |
pan/ltp-pan.c: Add file parsing protection
This patch adds protection and print warning when the command part of
the tests is empty.
A segmentation fault occurs when given the wrong format in test cases
file for example:
name command line
----- -----------------
dio10 diotest4 -b 65536 (O)
dio10 (X)
dio10 diotest4 -b 65536 (X)
In this patch, ltp-pan will return empty collection when the given
testcase files are wrongly formatted and cause ltp-pan to abort. The
warning message will indicate the name of the error testcase.
Signed-off-by: Dylan Chung <dylan@andestech.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
-rw-r--r-- | pan/ltp-pan.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/pan/ltp-pan.c b/pan/ltp-pan.c index 8ac484ec6..8b9fbe559 100644 --- a/pan/ltp-pan.c +++ b/pan/ltp-pan.c @@ -65,6 +65,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <ctype.h> #include "splitstr.h" #include "zoolib.h" @@ -1200,6 +1201,14 @@ static struct collection *get_collection(char *file, int optind, int argc, n->pcnt_f[1] = 's'; } n->name = strdup(strsep(&a, " \t")); + while (a != NULL && isspace(*a)) + a++; + if (a == NULL || a[0] == 0) { + fprintf(stderr, + "pan(%s): Testcase '%s' requires a command to execute.\n", + panname, n->name); + return NULL; + } n->cmdline = strdup(a); n->next = NULL; |