diff mbox series

[alsa-utils,5/5] aplay: Fix out-of-bound access in stereo VU meter drawing

Message ID 20210824094756.12540-6-tiwai@suse.de
State New
Headers show
Series [alsa-utils,1/5] aplay: Fix conversion of unsigned samples in peak calculation | expand

Commit Message

Takashi Iwai Aug. 24, 2021, 9:47 a.m. UTC
The left channel drawing of a stereo VU meter has a bug where it may
access a negative array index.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 aplay/aplay.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/aplay/aplay.c b/aplay/aplay.c
index a51a37ba34bd..63a4e3437fd9 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1758,10 +1758,12 @@  static void print_vu_meter_stereo(int *perc, int *maxperc)
 		if (c)
 			memset(line + bar_length + 6 + 1, '#', p);
 		else
-			memset(line + bar_length - p - 1, '#', p);
-		p = maxperc[c] * bar_length / 100;
-		if (p > bar_length)
-			p = bar_length;
+			memset(line + bar_length - p, '#', p);
+		p = maxperc[c] * bar_length / 100 - 1;
+		if (p < 0)
+			p = 0;
+		else if (p >= bar_length)
+			p = bar_length - 1;
 		if (c)
 			line[bar_length + 6 + 1 + p] = '+';
 		else