All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Athira Rajeev" <atrajeev@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name
Date: Wed, 02 Dec 2026 12:55:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-245814@kernel.org> (raw)
In-Reply-To: <20261202124337.10434-1-atrajeev@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf disasm: memory leak of dl->ins.name in
  disasm_line__parse_powerpc()
--

commit 672ddb2e1e6cdd2923c6ba2964448e4efdf6e08b
Author: Athira Rajeev <atrajeev@linux.ibm.com>

perf disasm powerpc: Don't use a string literal as the instruction name

This commit allocates an empty string with strdup("") in
disasm_line__parse_powerpc() when the disassembler is not used, avoiding an
invalid free() of a string literal in disasm_line__free().

> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> index 7c289b67b5bde..ac69ce93b0486 100644
> --- a/tools/perf/util/disasm.c
> +++ b/tools/perf/util/disasm.c
> @@ -901,10 +901,17 @@ static int disasm_line__parse_powerpc(struct disasm_line *dl, struct annotate_ar
>  	if (name_raw_insn[0] == '\0')
>  		return -1;
>  
> -	if (disasm)
> +	if (disasm) {
>  		ret = disasm_line__parse(name, namep, rawp);
> -	else
> -		*namep = "";
> +	} else {
> +		/*
> +		 * The name is freed in disasm_line__free() and may be replaced
> +		 * by check_ppc_insn(), so it must be heap allocated.
> +		 */
> +		*namep = strdup("");
> +		if (*namep == NULL)
> +			return -1;
> +	}
>  
>  	tmp_raw_insn = strndup(name_raw_insn, 11);
>  	if (tmp_raw_insn == NULL)

[Severity: Low]
Does this leak *namep (dl->ins.name) if strndup() fails right after
strdup("")?  Returning -1 sends the caller disasm_line__new() to
out_free_line, which frees dl->al and dl without freeing dl->ins.name.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202124337.10434-1-atrajeev@linux.ibm.com?part=1

      parent reply	other threads:[~2026-12-02 12:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:43 [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name Athira Rajeev
2026-12-02 12:43 ` [PATCH V2 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines Athira Rajeev
2026-12-02 12:59   ` sashiko-bot
2026-12-02 12:55 ` sashiko-bot [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=sashiko-outbox-245814@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atrajeev@linux.ibm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.