[PATCH v2 1/2] staging: most: sound: add sanity check for function argument

Christian Gromm christian.gromm at microchip.com
Tue Feb 2 16:21:05 UTC 2021


This patch checks the function parameter 'bytes' before doing the
subtraction to prevent memory corruption.

Signed-off-by: Christian Gromm <christian.gromm at microchip.com>
Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
---
v2: change if condition to avoid difference of subtraction becomes negative.

 drivers/staging/most/sound/sound.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 3a1a590..45befb8 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -86,6 +86,8 @@ static void swap_copy24(u8 *dest, const u8 *source, unsigned int bytes)
 {
 	unsigned int i = 0;
 
+	if (bytes < 2)
+		return;
 	while (i < bytes - 2) {
 		dest[i] = source[i + 2];
 		dest[i + 1] = source[i + 1];
-- 
2.7.4



More information about the devel mailing list