linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Riccardo Mancini <rickyman7@gmail.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Marco Elver <elver@google.com>,
	Sohaib Mohamed <sohaib.amhmd@gmail.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH] perf test: Avoid shell test description infinite loop
Date: Fri, 20 May 2022 11:17:36 -0300	[thread overview]
Message-ID: <YoejAP5Yfnh7ViIZ@kernel.org> (raw)
In-Reply-To: <20220517204144.645913-1-irogers@google.com>

Em Tue, May 17, 2022 at 01:41:44PM -0700, Ian Rogers escreveu:
> for_each_shell_test is already strict in expecting tests to be files and
> executable. It is sometimes possible when it iterates over all files
> that it finds one that is executable and lacks a newline character. When
> this happens the loop never terminates as it doesn't check for EOF. Add
> the EOF check to make this loop at least bounded by the file size.
> 
> If the description is returned as NULL then also skip the test.

Thanks, applied.

- Arnaldo

 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/tests/builtin-test.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 3c34cb766724..aa40eae1c9cf 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -279,6 +279,7 @@ static const char *shell_test__description(char *description, size_t size,
>  {
>  	FILE *fp;
>  	char filename[PATH_MAX];
> +	int ch;
>  
>  	path__join(filename, sizeof(filename), path, name);
>  	fp = fopen(filename, "r");
> @@ -286,7 +287,9 @@ static const char *shell_test__description(char *description, size_t size,
>  		return NULL;
>  
>  	/* Skip shebang */
> -	while (fgetc(fp) != '\n');
> +	do {
> +		ch = fgetc(fp);
> +	} while (ch != EOF && ch != '\n');
>  
>  	description = fgets(description, size, fp);
>  	fclose(fp);
> @@ -419,7 +422,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width,
>  			.priv = &st,
>  		};
>  
> -		if (!perf_test__matches(test_suite.desc, curr, argc, argv))
> +		if (test_suite.desc == NULL ||
> +		    !perf_test__matches(test_suite.desc, curr, argc, argv))
>  			continue;
>  
>  		st.file = ent->d_name;
> -- 
> 2.36.0.550.gb090851708-goog

-- 

- Arnaldo

      reply	other threads:[~2022-05-20 14:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 20:41 [PATCH] perf test: Avoid shell test description infinite loop Ian Rogers
2022-05-20 14:17 ` Arnaldo Carvalho de Melo [this message]

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=YoejAP5Yfnh7ViIZ@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=elver@google.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    --cc=sohaib.amhmd@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).