perf string: Avoid undefined NULL+1
Ian Rogers
reviewerPATCH 1/1 perf string: Avoid undefined NULL+1
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 <[email protected]>
--- tools/perf/util/string.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
tools/perf/util/string.c +12 -3
@@ -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; }
Signature · 1 line
2.47.0.371.ga323438b13-goog
Quoted 26 lines · Ian Rogers
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 <[email protected]>--- tools/perf/util/string.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)tools/perf/util/string.c +7
-2@@ -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; + }
tools/perf/util/string.c char *strpbrk_esc(char *str, const char *stopset) · line 273
Quoted 10 lines
tools/perf/util/string.c +5
-1+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 <[email protected]>
Quoted 22 lines · James Clark
Quoted 21 lines · Ian Rogers
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 <[email protected]>+++
b/tools/perf/util/string.ctools/perf/util/string.c +10
-2@@ -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;
Quoted 8 lines
tools/perf/util/string.c char *strpbrk_esc(char *str, const char *stopset) · line 273
Quoted 6 lines
tools/perf/util/string.c +2
-1+ } str = ptr +1 ; - }while (ptr && *(ptr -1 ) =='\\' && *(ptr -2 ) !='\\' ); + }while (ptr[-1 ] =='\\' && ptr[-2 ] !='\\' );return ptr; }Reviewed-by James Clark <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo