* [PATCH v1] perf string: Avoid undefined NULL+1
@ 2024-11-20 6:52 Ian Rogers
2024-12-09 11:49 ` James Clark
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2024-11-20 6:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, Masami Hiramatsu (Google),
linux-perf-users, linux-kernel
While the value NULL+1 is never used it triggers a ubsan
warning. Restructure and comment the loop to avoid this.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/string.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 308fc7ec88cc..c0e927bbadf6 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -254,11 +254,20 @@ char *strpbrk_esc(char *str, const char *stopset)
do {
ptr = strpbrk(str, stopset);
- if (ptr == str ||
- (ptr == str + 1 && *(ptr - 1) != '\\'))
+ if (!ptr) {
+ /* stopset not in str. */
break;
+ }
+ if (ptr == str) {
+ /* stopset character is first in str. */
+ break;
+ }
+ if (ptr == str + 1 && str[0] != '\\') {
+ /* stopset chacter is second and wasn't preceded by a '\'. */
+ break;
+ }
str = ptr + 1;
- } while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
+ } while (ptr[-1] == '\\' && ptr[-2] != '\\');
return ptr;
}
--
2.47.0.371.ga323438b13-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] perf string: Avoid undefined NULL+1
2024-11-20 6:52 [PATCH v1] perf string: Avoid undefined NULL+1 Ian Rogers
@ 2024-12-09 11:49 ` James Clark
2024-12-12 18:54 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: James Clark @ 2024-12-09 11:49 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Masami Hiramatsu (Google)
Cc: linux-perf-users, linux-kernel, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Kan Liang, Peter Zijlstra, Ingo Molnar
On 20/11/2024 6:52 am, Ian Rogers wrote:
> While the value NULL+1 is never used it triggers a ubsan
> warning. Restructure and comment the loop to avoid this.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/util/string.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
> index 308fc7ec88cc..c0e927bbadf6 100644
> --- a/tools/perf/util/string.c
> +++ b/tools/perf/util/string.c
> @@ -254,11 +254,20 @@ char *strpbrk_esc(char *str, const char *stopset)
>
> do {
> ptr = strpbrk(str, stopset);
> - if (ptr == str ||
> - (ptr == str + 1 && *(ptr - 1) != '\\'))
> + if (!ptr) {
> + /* stopset not in str. */
> break;
> + }
> + if (ptr == str) {
> + /* stopset character is first in str. */
> + break;
> + }
> + if (ptr == str + 1 && str[0] != '\\') {
> + /* stopset chacter is second and wasn't preceded by a '\'. */
> + break;
> + }
> str = ptr + 1;
> - } while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
> + } while (ptr[-1] == '\\' && ptr[-2] != '\\');
>
> return ptr;
> }
Reviewed-by: James Clark <james.clark@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] perf string: Avoid undefined NULL+1
2024-12-09 11:49 ` James Clark
@ 2024-12-12 18:54 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-12-12 18:54 UTC (permalink / raw)
To: James Clark
Cc: Ian Rogers, Namhyung Kim, Masami Hiramatsu (Google),
linux-perf-users, linux-kernel, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Kan Liang, Peter Zijlstra, Ingo Molnar
On Mon, Dec 09, 2024 at 11:49:15AM +0000, James Clark wrote:
> On 20/11/2024 6:52 am, Ian Rogers wrote:
> > While the value NULL+1 is never used it triggers a ubsan
> > warning. Restructure and comment the loop to avoid this.
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > +++ b/tools/perf/util/string.c
> > @@ -254,11 +254,20 @@ char *strpbrk_esc(char *str, const char *stopset)
> > do {
> > ptr = strpbrk(str, stopset);
> > - if (ptr == str ||
> > - (ptr == str + 1 && *(ptr - 1) != '\\'))
> > + if (!ptr) {
> > + /* stopset not in str. */
> > break;
> > + }
> > + if (ptr == str) {
> > + /* stopset character is first in str. */
> > + break;
> > + }
> > + if (ptr == str + 1 && str[0] != '\\') {
> > + /* stopset chacter is second and wasn't preceded by a '\'. */
> > + break;
> > + }
> > str = ptr + 1;
> > - } while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
> > + } while (ptr[-1] == '\\' && ptr[-2] != '\\');
> > return ptr;
> > }
> Reviewed-by: James Clark <james.clark@linaro.org>
Thanks, applied to perf-tools-next,
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-12 18:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-20 6:52 [PATCH v1] perf string: Avoid undefined NULL+1 Ian Rogers
2024-12-09 11:49 ` James Clark
2024-12-12 18:54 ` Arnaldo Carvalho de Melo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.