public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection
@ 2019-11-15  5:29 Dylan Chung
  2019-11-15 10:03 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Dylan Chung @ 2019-11-15  5:29 UTC (permalink / raw)
  To: ltp

A segmentation fault occurs 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)
This patch adds protection and print warning when the command part
of the tests is empty or multiple whitespaces.

Signed-off-by: Dylan Chung <dylan@andestech.com>
---
 pan/ltp-pan.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pan/ltp-pan.c b/pan/ltp-pan.c
index 8ac484ec6..470bcbfc5 100644
--- a/pan/ltp-pan.c
+++ b/pan/ltp-pan.c
@@ -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 || strlen(a) == 0) {
+				fprintf(stderr,
+					"pan(%s): Testcase '%s' requires a command to execute.\n",
+					panname, n->name);
+				return 0;
+			}
 			n->cmdline = strdup(a);
 			n->next = NULL;
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection
  2019-11-15  5:29 [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection Dylan Chung
@ 2019-11-15 10:03 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2019-11-15 10:03 UTC (permalink / raw)
  To: ltp

Hi!
> A segmentation fault occurs 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)
> This patch adds protection and print warning when the command part
> of the tests is empty or multiple whitespaces.

And the expected action here is that we return empty collection when the
file is wrongly formatted and ltp-pan aborts, right?

You should probably write something along these lines here as well.

> Signed-off-by: Dylan Chung <dylan@andestech.com>
> ---
>  pan/ltp-pan.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/pan/ltp-pan.c b/pan/ltp-pan.c
> index 8ac484ec6..470bcbfc5 100644
> --- a/pan/ltp-pan.c
> +++ b/pan/ltp-pan.c
> @@ -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 || strlen(a) == 0) {
                                           ^
					   Maybe just || a[0] == 0 there is
					   no point in using strlen for
					   checking for empty string...
> +				fprintf(stderr,
> +					"pan(%s): Testcase '%s' requires a command to execute.\n",
> +					panname, n->name);
> +				return 0;
                                       ^
				       This should be NULL
> +			}
>  			n->cmdline = strdup(a);
>  			n->next = NULL;

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-15 10:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-15  5:29 [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection Dylan Chung
2019-11-15 10:03 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox