Skip to content

Commit 44eeb08

Browse files
committed
ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs
Some code in HD-audio driver calls snprintf() in a loop and still expects that the return value were actually written size, while snprintf() returns the expected would-be length instead. When the given buffer limit were small, this leads to a buffer overflow. Use scnprintf() for addressing those issues. It returns the actually written size unlike snprintf(). Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent cc5049a commit 44eeb08

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

sound/hda/hdmi_chmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void snd_hdac_print_channel_allocation(int spk_alloc, char *buf, int buflen)
250250

251251
for (i = 0, j = 0; i < ARRAY_SIZE(cea_speaker_allocation_names); i++) {
252252
if (spk_alloc & (1 << i))
253-
j += snprintf(buf + j, buflen - j, " %s",
253+
j += scnprintf(buf + j, buflen - j, " %s",
254254
cea_speaker_allocation_names[i]);
255255
}
256256
buf[j] = '\0'; /* necessary when j == 0 */

sound/pci/hda/hda_codec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4022,7 +4022,7 @@ void snd_print_pcm_bits(int pcm, char *buf, int buflen)
40224022

40234023
for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
40244024
if (pcm & (AC_SUPPCM_BITS_8 << i))
4025-
j += snprintf(buf + j, buflen - j, " %d", bits[i]);
4025+
j += scnprintf(buf + j, buflen - j, " %d", bits[i]);
40264026

40274027
buf[j] = '\0'; /* necessary when j == 0 */
40284028
}

sound/pci/hda/hda_eld.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void hdmi_print_pcm_rates(int pcm, char *buf, int buflen)
360360

361361
for (i = 0, j = 0; i < ARRAY_SIZE(alsa_rates); i++)
362362
if (pcm & (1 << i))
363-
j += snprintf(buf + j, buflen - j, " %d",
363+
j += scnprintf(buf + j, buflen - j, " %d",
364364
alsa_rates[i]);
365365

366366
buf[j] = '\0'; /* necessary when j == 0 */

sound/pci/hda/hda_sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static ssize_t init_verbs_show(struct device *dev,
222222
int i, len = 0;
223223
mutex_lock(&codec->user_mutex);
224224
snd_array_for_each(&codec->init_verbs, i, v) {
225-
len += snprintf(buf + len, PAGE_SIZE - len,
225+
len += scnprintf(buf + len, PAGE_SIZE - len,
226226
"0x%02x 0x%03x 0x%04x\n",
227227
v->nid, v->verb, v->param);
228228
}
@@ -272,7 +272,7 @@ static ssize_t hints_show(struct device *dev,
272272
int i, len = 0;
273273
mutex_lock(&codec->user_mutex);
274274
snd_array_for_each(&codec->hints, i, hint) {
275-
len += snprintf(buf + len, PAGE_SIZE - len,
275+
len += scnprintf(buf + len, PAGE_SIZE - len,
276276
"%s = %s\n", hint->key, hint->val);
277277
}
278278
mutex_unlock(&codec->user_mutex);

0 commit comments

Comments
 (0)