In the function r600_test_dma the max_width and max_height can be set to
zero. These variables are later used to do a modulo operation which can
lead to unexpected behavior if they are zero. This patch corrects that
by first checking if the max_width or max_height are zero and if they
are it sets width or height to one. Issue was discoverd by Coverity.

CID: 1361542, 1361543

Signed-off-by: Jakob Sinclair <sinclair.ja...@openmailbox.org>
---
 src/gallium/drivers/radeon/r600_test_dma.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_test_dma.c 
b/src/gallium/drivers/radeon/r600_test_dma.c
index c203b4d..37d6202 100644
--- a/src/gallium/drivers/radeon/r600_test_dma.c
+++ b/src/gallium/drivers/radeon/r600_test_dma.c
@@ -345,8 +345,15 @@ void r600_test_dma(struct r600_common_screen *rscreen)
                                        dstx = rand() % (tdst.width0 - width + 
1) & ~0x7;
                                        dsty = rand() % (tdst.height0 - height 
+ 1) & ~0x7;
                                } else {
-                                       width = (rand() % max_width) + 1;
-                                       height = (rand() % max_height) + 1;
+                                       if (max_width == 0)
+                                               width = 1;
+                                       else
+                                               width = (rand() % max_width) + 
1;
+
+                                       if (max_height == 0)
+                                               height = 1;
+                                       else
+                                               height = (rand() % max_height) 
+ 1;
 
                                        srcx = rand() % (tsrc.width0 - width + 
1);
                                        srcy = rand() % (tsrc.height0 - height 
+ 1);
-- 
2.8.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to