[1/2] perf dwarf-aux: Fix off-by-one in die_get_varname()

Message ID 20230612234102.3909116-1-namhyung@kernel.org
State New
Headers
Series [1/2] perf dwarf-aux: Fix off-by-one in die_get_varname() |

Commit Message

Namhyung Kim June 12, 2023, 11:41 p.m. UTC
  The die_get_varname() returns "(unknown_type)" string if it failed to
find a type for the variable.  But it had a space before the opening
parenthesis and it made the closing parenthesis cut off due to the
off-by-one in the string length (14).

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/dwarf-aux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Arnaldo Carvalho de Melo June 13, 2023, 2:32 p.m. UTC | #1
Em Mon, Jun 12, 2023 at 04:41:01PM -0700, Namhyung Kim escreveu:
> The die_get_varname() returns "(unknown_type)" string if it failed to
> find a type for the variable.  But it had a space before the opening
> parenthesis and it made the closing parenthesis cut off due to the
> off-by-one in the string length (14).

Thanks, applied and added:

Fixes: 88fd633cdfa19060 ("perf probe: No need to use formatting strbuf method")

I introduced this long ago :-\

- Arnaldo
 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/dwarf-aux.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index e4593a71556b..1ac88b79687d 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
>  	ret = die_get_typename(vr_die, buf);
>  	if (ret < 0) {
>  		pr_debug("Failed to get type, make it unknown.\n");
> -		ret = strbuf_add(buf, " (unknown_type)", 14);
> +		ret = strbuf_add(buf, "(unknown_type)", 14);
>  	}
>  
>  	return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
> -- 
> 2.41.0.162.gfafddb0af9-goog
  
Arnaldo Carvalho de Melo June 13, 2023, 2:34 p.m. UTC | #2
Em Mon, Jun 12, 2023 at 04:41:01PM -0700, Namhyung Kim escreveu:
> The die_get_varname() returns "(unknown_type)" string if it failed to
> find a type for the variable.  But it had a space before the opening
> parenthesis and it made the closing parenthesis cut off due to the
> off-by-one in the string length (14).

Thanks, applied both patches.

- Arnaldo

 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/dwarf-aux.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index e4593a71556b..1ac88b79687d 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
>  	ret = die_get_typename(vr_die, buf);
>  	if (ret < 0) {
>  		pr_debug("Failed to get type, make it unknown.\n");
> -		ret = strbuf_add(buf, " (unknown_type)", 14);
> +		ret = strbuf_add(buf, "(unknown_type)", 14);
>  	}
>  
>  	return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
> -- 
> 2.41.0.162.gfafddb0af9-goog
>
  

Patch

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index e4593a71556b..1ac88b79687d 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -1103,7 +1103,7 @@  int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
 	ret = die_get_typename(vr_die, buf);
 	if (ret < 0) {
 		pr_debug("Failed to get type, make it unknown.\n");
-		ret = strbuf_add(buf, " (unknown_type)", 14);
+		ret = strbuf_add(buf, "(unknown_type)", 14);
 	}
 
 	return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));