staging: most: sound: add sanity check for function argument
authorChristian Gromm <christian.gromm@microchip.com>
Tue, 2 Feb 2021 16:21:05 +0000 (17:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Feb 2021 16:13:46 +0000 (17:13 +0100)
This patch checks the function parameter 'bytes' before doing the
subtraction to prevent memory corruption.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/1612282865-21846-1-git-send-email-christian.gromm@microchip.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/most/sound/sound.c

index 3a1a590..45befb8 100644 (file)
@@ -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];