[Mesa-dev] [PATCH 3/4] gallium/hud: prevent an infinite loop

Marek Olšák maraeo at gmail.com
Tue Feb 21 21:09:27 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

v2: use UINT64_MAX / 11

---
 src/gallium/auxiliary/hud/hud_context.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index aaa52d5..c44f8c0 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -724,23 +724,24 @@ hud_pane_set_max_value(struct hud_pane *pane, uint64_t value)
    uint64_t exp10;
    int i;
 
    /* The following code determines the max_value in the graph as well as
     * how many describing lines are drawn. The max_value is rounded up,
     * so that all drawn numbers are rounded for readability.
     * We want to print multiples of a simple number instead of multiples of
     * hard-to-read numbers like 1.753.
     */
 
-   /* Find the left-most digit. */
+   /* Find the left-most digit. Make sure exp10 * 10 and fixup_bytes doesn't
+    * overflow. (11 is safe) */
    exp10 = 1;
-   for (i = 0; value > 9 * exp10; i++) {
+   for (i = 0; exp10 <= UINT64_MAX / 11 && exp10 * 9 < value; i++) {
       exp10 *= 10;
       fixup_bytes(pane->type, i + 1, &exp10);
    }
 
    leftmost_digit = DIV_ROUND_UP(value, exp10);
 
    /* Round 9 to 10. */
    if (leftmost_digit == 9) {
       leftmost_digit = 1;
       exp10 *= 10;
-- 
2.7.4



More information about the mesa-dev mailing list