From 195c048d1c1f603690f6b42cfff721901511e08b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 6 May 2026 11:55:43 +0200 Subject: [PATCH] audioconvert: use strbuf to construct the channel names This handles overflow and errors correctly, unlike snprintf which might return -1 or the size that would have been written if truncated, causing overwrite later. --- spa/plugins/audioconvert/audioconvert.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 440fc6931..bb80252be 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -2266,10 +2266,12 @@ static void set_volume(struct impl *this) static char *format_position(char *str, size_t len, uint32_t channels, uint32_t *position) { - uint32_t i, idx = 0; + uint32_t i; char buf[8]; + struct spa_strbuf b; + spa_strbuf_init(&b, str, len); for (i = 0; i < channels; i++) - idx += snprintf(str + idx, len - idx, "%s%s", i == 0 ? "" : " ", + spa_strbuf_append(&b, "%s%s", i == 0 ? "" : " ", spa_type_audio_channel_make_short_name(position[i], buf, sizeof(buf), "UNK")); return str;