public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Dylan Chung <dylan@andestech.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection
Date: Fri, 15 Nov 2019 13:29:06 +0800	[thread overview]
Message-ID: <20191115052906.2643-1-dylan@andestech.com> (raw)

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


             reply	other threads:[~2019-11-15  5:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15  5:29 Dylan Chung [this message]
2019-11-15 10:03 ` [LTP] [PATCH] pan/ltp-pan.c: Add file parsing protection Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191115052906.2643-1-dylan@andestech.com \
    --to=dylan@andestech.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox