From bbf81b18887724c8b1ab2beedfd70cc72fb8d0ca Mon Sep 17 00:00:00 2001 From: Halcao Date: Tue, 23 Apr 2024 12:53:04 +0800 Subject: [PATCH] Fix buffer overflow in size calculation Moved the multiplication of 'test_size' by 1024 before comparing it to 'BUFFER_SIZE'. This prevents a potential buffer overflow when 'test_size' equals 'BUFFER_SIZE'. --- linux-user-space-dma/Software/User/dma-proxy-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user-space-dma/Software/User/dma-proxy-test.c b/linux-user-space-dma/Software/User/dma-proxy-test.c index aa8ea4d..41a431a 100644 --- a/linux-user-space-dma/Software/User/dma-proxy-test.c +++ b/linux-user-space-dma/Software/User/dma-proxy-test.c @@ -350,9 +350,9 @@ int main(int argc, char *argv[]) * convert it from KB to bytes */ test_size = atoi(argv[2]); + test_size *= 1024; if (test_size > BUFFER_SIZE) test_size = BUFFER_SIZE; - test_size *= 1024; /* Verify is off by default to get pure performance of the DMA transfers without the CPU accessing all the data * to slow it down.