public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
To: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Mark Brown" <broonie@kernel.org>
Cc: Cezary Rojewski <cezary.rojewski@intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
	alsa-devel@alsa-project.org, linux-sound@vger.kernel.org,
	Jason Montleon <jmontleo@redhat.com>
Subject: Re: [PATCH 1/4] ASoC: topology: Fix references to freed memory
Date: Thu, 13 Jun 2024 09:31:42 +0200	[thread overview]
Message-ID: <be6d9c07-1b26-408a-93ec-64fcbec73e80@linux.intel.com> (raw)
In-Reply-To: <750f8ab4-f283-44e0-9b6c-57176bdbf59e@linux.intel.com>

On 6/13/2024 8:44 AM, Péter Ujfalusi wrote:
> 
> On 13/06/2024 09:29, Péter Ujfalusi wrote:
>>>>> +		route->sink = devm_kmemdup(tplg->dev, elem->sink,
>>>>> +					   min(strlen(elem->sink), SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
>>>
>>> Initially I did not see why this breaks, but then:
>>>
>>> The strlen() function calculates the length of the string pointed to by
>>> s, excluding the terminating null byte ('\0').
>>>
>>> Likely the fix is as simple as:
>>> min(strlen(elem->sink) + 1, SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
>>
>> or better yet:
>> route->sink = devm_kasprintf(tplg->dev, GFP_KERNEL, "%s", elem->sink);
> 
> or even better:
> route->sink = devm_kstrdup(tplg->dev, elem->sink, GFP_KERNEL);
> 

I guess I might have overdid it a bit, let's go with devm_kstrdup for 
all of them, as it should just work unless someone tries to corrupt 
topology file.

  reply	other threads:[~2024-06-13  7:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-03 10:28 [PATCH 0/4] ASoC: topology: Fix route memory corruption Amadeusz Sławiński
2024-06-03 10:28 ` [PATCH 1/4] ASoC: topology: Fix references to freed memory Amadeusz Sławiński
2024-06-13  5:58   ` Pierre-Louis Bossart
2024-06-13  6:27     ` Péter Ujfalusi
2024-06-13  6:29       ` Péter Ujfalusi
2024-06-13  6:44         ` Péter Ujfalusi
2024-06-13  7:31           ` Amadeusz Sławiński [this message]
2024-06-03 10:28 ` [PATCH 2/4] ASoC: Intel: avs: Fix route override Amadeusz Sławiński
2024-06-03 10:28 ` [PATCH 3/4] ASoC: topology: Do not assign fields that are already set Amadeusz Sławiński
2024-06-03 10:28 ` [PATCH 4/4] ASoC: topology: Clean up route loading Amadeusz Sławiński
2024-06-11 16:12 ` [PATCH 0/4] ASoC: topology: Fix route memory corruption Mark Brown

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=be6d9c07-1b26-408a-93ec-64fcbec73e80@linux.intel.com \
    --to=amadeuszx.slawinski@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=jmontleo@redhat.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.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