Skip to content

Commit 6c89ffe

Browse files
tiwaibroonie
authored andcommitted
ASoC: pcm: Fix possible buffer overflow in dpcm state sysfs output
dpcm_show_state() invokes multiple snprintf() calls to concatenate formatted strings on the fixed size buffer. The usage of snprintf() is supposed for avoiding the buffer overflow, but it doesn't work as expected because snprintf() doesn't return the actual output size but the size to be written. Fix this bug by replacing all snprintf() calls with scnprintf() calls. Fixes: f86dcef ("ASoC: dpcm: Add debugFS support for DPCM") Signed-off-by: Takashi Iwai <[email protected]> Acked-by: Cezary Rojewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 549cd0b commit 6c89ffe

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

sound/soc/soc-pcm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,27 +3171,27 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
31713171
unsigned long flags;
31723172

31733173
/* FE state */
3174-
offset += snprintf(buf + offset, size - offset,
3174+
offset += scnprintf(buf + offset, size - offset,
31753175
"[%s - %s]\n", fe->dai_link->name,
31763176
stream ? "Capture" : "Playback");
31773177

3178-
offset += snprintf(buf + offset, size - offset, "State: %s\n",
3178+
offset += scnprintf(buf + offset, size - offset, "State: %s\n",
31793179
dpcm_state_string(fe->dpcm[stream].state));
31803180

31813181
if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
31823182
(fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
3183-
offset += snprintf(buf + offset, size - offset,
3183+
offset += scnprintf(buf + offset, size - offset,
31843184
"Hardware Params: "
31853185
"Format = %s, Channels = %d, Rate = %d\n",
31863186
snd_pcm_format_name(params_format(params)),
31873187
params_channels(params),
31883188
params_rate(params));
31893189

31903190
/* BEs state */
3191-
offset += snprintf(buf + offset, size - offset, "Backends:\n");
3191+
offset += scnprintf(buf + offset, size - offset, "Backends:\n");
31923192

31933193
if (list_empty(&fe->dpcm[stream].be_clients)) {
3194-
offset += snprintf(buf + offset, size - offset,
3194+
offset += scnprintf(buf + offset, size - offset,
31953195
" No active DSP links\n");
31963196
goto out;
31973197
}
@@ -3201,16 +3201,16 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
32013201
struct snd_soc_pcm_runtime *be = dpcm->be;
32023202
params = &dpcm->hw_params;
32033203

3204-
offset += snprintf(buf + offset, size - offset,
3204+
offset += scnprintf(buf + offset, size - offset,
32053205
"- %s\n", be->dai_link->name);
32063206

3207-
offset += snprintf(buf + offset, size - offset,
3207+
offset += scnprintf(buf + offset, size - offset,
32083208
" State: %s\n",
32093209
dpcm_state_string(be->dpcm[stream].state));
32103210

32113211
if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
32123212
(be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
3213-
offset += snprintf(buf + offset, size - offset,
3213+
offset += scnprintf(buf + offset, size - offset,
32143214
" Hardware Params: "
32153215
"Format = %s, Channels = %d, Rate = %d\n",
32163216
snd_pcm_format_name(params_format(params)),

0 commit comments

Comments
 (0)