From 60a53d9eb550c5142b695b77a99dbc6b7abb5cb2 Mon Sep 17 00:00:00 2001 From: "[CST] Bas" Date: Thu, 12 Jun 2014 08:18:47 +0200 Subject: [PATCH] src/gui/streaminfo2.cpp: fix possible integer overflow if fe driver reports very high values. The fix is to check for overflow and if so just return max_y. --- src/gui/streaminfo2.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gui/streaminfo2.cpp b/src/gui/streaminfo2.cpp index c44fd40e2..8531fd36a 100644 --- a/src/gui/streaminfo2.cpp +++ b/src/gui/streaminfo2.cpp @@ -369,13 +369,20 @@ void CStreamInfo2::paint_signal_fe(struct bitrate br, struct feSignal s) // -- calc y from max_range and max_y int CStreamInfo2::y_signal_fe (unsigned long value, unsigned long max_value, int max_y) { - long l; + unsigned long long m; + unsigned long l; if (!max_value) max_value = 1; - l = ((long) max_y * (long) value) / (long) max_value; - if (l > max_y) + // we use a 64 bits int here to detect integer overflow + // and if it overflows, just return max_y + m = (unsigned long long)value * max_y; + if (m > 0xffffffff) + return max_y; + + l = m / max_value; + if (l > (unsigned long)max_y) l = max_y; return (int) l;