From: wangdich9700@163.com
To: tiwai@suse.com, perex@perex.cz, wangdicheng@kylinos.cn,
wangdich9700@163.com
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting
Date: Wed, 3 Jun 2026 17:11:00 +0800 [thread overview]
Message-ID: <20260603091102.231370-2-wangdich9700@163.com> (raw)
In-Reply-To: <20260603091102.231370-1-wangdich9700@163.com>
From: wangdicheng <wangdicheng@kylinos.cn>
The current code uses sprintf() to format control names without bounds
checking, which could lead to buffer overflow if PCM index is large.
Replace sprintf with snprintf to ensure buffer safety.
The ctl_name buffer is 48 bytes, and the formatted string could exceed
this with large PCM index values. Using snprintf with sizeof(ctl_name)
prevents potential buffer overflow.
Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
sound/usb/qcom/mixer_usb_offload.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/usb/qcom/mixer_usb_offload.c b/sound/usb/qcom/mixer_usb_offload.c
index 2adeb64f4d33..48e55d5872d5 100644
--- a/sound/usb/qcom/mixer_usb_offload.c
+++ b/sound/usb/qcom/mixer_usb_offload.c
@@ -128,7 +128,7 @@ int snd_usb_offload_create_ctl(struct snd_usb_audio *chip, struct device *bedev)
*/
chip_kctl->private_value = as->pcm_index |
chip->card->number << 16;
- sprintf(ctl_name, "USB Offload Playback Card Route PCM#%d",
+ snprintf(ctl_name, sizeof(ctl_name), "USB Offload Playback Card Route PCM#%d",
as->pcm_index);
chip_kctl->name = ctl_name;
ret = snd_ctl_add(chip->card, snd_ctl_new1(chip_kctl, bedev));
@@ -143,7 +143,7 @@ int snd_usb_offload_create_ctl(struct snd_usb_audio *chip, struct device *bedev)
*/
chip_kctl->private_value = as->pcm_index |
chip->card->number << 16;
- sprintf(ctl_name, "USB Offload Playback PCM Route PCM#%d",
+ snprintf(ctl_name, sizeof(ctl_name), "USB Offload Playback PCM Route PCM#%d",
as->pcm_index);
chip_kctl->name = ctl_name;
ret = snd_ctl_add(chip->card, snd_ctl_new1(chip_kctl, bedev));
--
2.25.1
next prev parent reply other threads:[~2026-06-03 9:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
2026-06-03 9:11 ` wangdich9700 [this message]
2026-06-03 9:11 ` [PATCH 3/4] ALSA: usb-audio: qcom: Fix return value in qc_usb_audio_offload_fill_avail_pcms wangdich9700
2026-06-03 9:11 ` [PATCH 4/4] ALSA: usb-audio: qcom: Use PAGE_ALIGN macro for buffer size calculation wangdich9700
2026-06-04 8:16 ` [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload Takashi Iwai
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=20260603091102.231370-2-wangdich9700@163.com \
--to=wangdich9700@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=wangdicheng@kylinos.cn \
/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
all inboxes | Powered by JetHome®