pan/ltp-pan.c: Add file parsing protection
PATCH v2 1/1 pan/ltp-pan.c: Add file parsing protection
------------------v1->v2:
1.replace "strlen(a)==0" with "a[0]== 0".
2.Add more detail description in commit message.
------------------
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 <[email protected]>
--- pan/ltp-pan.c | 8 ++++++++ 1 file changed, 8 insertions(+)
pan/ltp-pan.c +8 -0
@@ -1200,6 +1200,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 ;
Signature · 1 line
2.17.0
PATCH v2 1/1 pan/ltp-pan.c: Add file parsing protection
Hi!
I've added #include <ctype.h> to the patch to have th isspace() defined and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]