mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: perex@perex.cz
Cc: tiwai@suse.com, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org, pengpeng@iscas.ac.cn
Subject: [PATCH 1/7] ALSA: asihpi: bound control name formatting
Date: Mon, 23 Mar 2026 15:03:10 +0800	[thread overview]
Message-ID: <20260323070310.42827-1-pengpeng@iscas.ac.cn> (raw)

asihpi_ctl_init() builds mixer control names in the fixed 44-byte
hpi_ctl->name buffer, but it currently does so with sprintf(). Some
source/destination node names are already long enough that combining both
endpoints, their indices, the direction prefix, and the control name can
run past the end of the buffer.

Switch the formatting to snprintf() so the driver never writes past the
ALSA control name storage.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 sound/pci/asihpi/asihpi.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index 3a64d0562803..f8bcc05c8742 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -1384,22 +1384,25 @@ static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
 		dir = "Playback "; /* PCM Playback source, or  output node */
 
 	if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
-		sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
+		snprintf(hpi_ctl->name, sizeof(hpi_ctl->name),
+			 "%s %d %s %d %s%s",
 			asihpi_src_names[hpi_ctl->src_node_type],
 			hpi_ctl->src_node_index,
 			asihpi_dst_names[hpi_ctl->dst_node_type],
 			hpi_ctl->dst_node_index,
 			dir, name);
 	else if (hpi_ctl->dst_node_type) {
-		sprintf(hpi_ctl->name, "%s %d %s%s",
-		asihpi_dst_names[hpi_ctl->dst_node_type],
-		hpi_ctl->dst_node_index,
-		dir, name);
+		snprintf(hpi_ctl->name, sizeof(hpi_ctl->name),
+			 "%s %d %s%s",
+			 asihpi_dst_names[hpi_ctl->dst_node_type],
+			 hpi_ctl->dst_node_index,
+			 dir, name);
 	} else {
-		sprintf(hpi_ctl->name, "%s %d %s%s",
-		asihpi_src_names[hpi_ctl->src_node_type],
-		hpi_ctl->src_node_index,
-		dir, name);
+		snprintf(hpi_ctl->name, sizeof(hpi_ctl->name),
+			 "%s %d %s%s",
+			 asihpi_src_names[hpi_ctl->src_node_type],
+			 hpi_ctl->src_node_index,
+			 dir, name);
 	}
 }
 
@@ -2957,4 +2960,3 @@ static void __exit snd_asihpi_exit(void)
 
 module_init(snd_asihpi_init)
 module_exit(snd_asihpi_exit)
-
-- 
2.50.1 (Apple Git-155)


             reply	other threads:[~2026-03-23  7:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23  7:03 Pengpeng Hou [this message]
2026-03-27  9:42 ` 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=20260323070310.42827-1-pengpeng@iscas.ac.cn \
    --to=pengpeng@iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --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

all inboxes | Powered by JetHome®